| 1 | /* Parser for C and Objective-C. |
| 2 | Copyright (C) 1987-2017 Free Software Foundation, Inc. |
| 3 | |
| 4 | Parser actions based on the old Bison parser; structure somewhat |
| 5 | influenced by and fragments based on the C++ parser. |
| 6 | |
| 7 | This file is part of GCC. |
| 8 | |
| 9 | GCC is free software; you can redistribute it and/or modify it under |
| 10 | the terms of the GNU General Public License as published by the Free |
| 11 | Software Foundation; either version 3, or (at your option) any later |
| 12 | version. |
| 13 | |
| 14 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 15 | WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 17 | for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with GCC; see the file COPYING3. If not see |
| 21 | <http://www.gnu.org/licenses/>. */ |
| 22 | |
| 23 | /* TODO: |
| 24 | |
| 25 | Make sure all relevant comments, and all relevant code from all |
| 26 | actions, brought over from old parser. Verify exact correspondence |
| 27 | of syntax accepted. |
| 28 | |
| 29 | Add testcases covering every input symbol in every state in old and |
| 30 | new parsers. |
| 31 | |
| 32 | Include full syntax for GNU C, including erroneous cases accepted |
| 33 | with error messages, in syntax productions in comments. |
| 34 | |
| 35 | Make more diagnostics in the front end generally take an explicit |
| 36 | location rather than implicitly using input_location. */ |
| 37 | |
| 38 | #include "config.h" |
| 39 | #include "system.h" |
| 40 | #include "coretypes.h" |
| 41 | #include "target.h" |
| 42 | #include "function.h" |
| 43 | #include "c-tree.h" |
| 44 | #include "timevar.h" |
| 45 | #include "stringpool.h" |
| 46 | #include "cgraph.h" |
| 47 | #include "attribs.h" |
| 48 | #include "stor-layout.h" |
| 49 | #include "varasm.h" |
| 50 | #include "trans-mem.h" |
| 51 | #include "c-family/c-pragma.h" |
| 52 | #include "c-lang.h" |
| 53 | #include "c-family/c-objc.h" |
| 54 | #include "plugin.h" |
| 55 | #include "omp-general.h" |
| 56 | #include "omp-offload.h" |
| 57 | #include "builtins.h" |
| 58 | #include "gomp-constants.h" |
| 59 | #include "c-family/c-indentation.h" |
| 60 | #include "gimple-expr.h" |
| 61 | #include "context.h" |
| 62 | #include "gcc-rich-location.h" |
| 63 | #include "c-parser.h" |
| 64 | #include "gimple-parser.h" |
| 65 | #include "read-rtl-function.h" |
| 66 | #include "run-rtl-passes.h" |
| 67 | #include "intl.h" |
| 68 | |
| 69 | /* We need to walk over decls with incomplete struct/union/enum types |
| 70 | after parsing the whole translation unit. |
| 71 | In finish_decl(), if the decl is static, has incomplete |
| 72 | struct/union/enum type, it is appeneded to incomplete_record_decls. |
| 73 | In c_parser_translation_unit(), we iterate over incomplete_record_decls |
| 74 | and report error if any of the decls are still incomplete. */ |
| 75 | |
| 76 | vec<tree> incomplete_record_decls; |
| 77 | |
| 78 | void |
| 79 | set_c_expr_source_range (c_expr *expr, |
| 80 | location_t start, location_t finish) |
| 81 | { |
| 82 | expr->src_range.m_start = start; |
| 83 | expr->src_range.m_finish = finish; |
| 84 | if (expr->value) |
| 85 | set_source_range (expr->value, start, finish); |
| 86 | } |
| 87 | |
| 88 | void |
| 89 | set_c_expr_source_range (c_expr *expr, |
| 90 | source_range src_range) |
| 91 | { |
| 92 | expr->src_range = src_range; |
| 93 | if (expr->value) |
| 94 | set_source_range (expr->value, src_range); |
| 95 | } |
| 96 | |
| 97 | |
| 98 | /* Initialization routine for this file. */ |
| 99 | |
| 100 | void |
| 101 | c_parse_init (void) |
| 102 | { |
| 103 | /* The only initialization required is of the reserved word |
| 104 | identifiers. */ |
| 105 | unsigned int i; |
| 106 | tree id; |
| 107 | int mask = 0; |
| 108 | |
| 109 | /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in |
| 110 | the c_token structure. */ |
| 111 | gcc_assert (RID_MAX <= 255); |
| 112 | |
| 113 | mask |= D_CXXONLY; |
| 114 | if (!flag_isoc99) |
| 115 | mask |= D_C99; |
| 116 | if (flag_no_asm) |
| 117 | { |
| 118 | mask |= D_ASM | D_EXT; |
| 119 | if (!flag_isoc99) |
| 120 | mask |= D_EXT89; |
| 121 | } |
| 122 | if (!c_dialect_objc ()) |
| 123 | mask |= D_OBJC | D_CXX_OBJC; |
| 124 | |
| 125 | ridpointers = ggc_cleared_vec_alloc<tree> ((int) RID_MAX); |
| 126 | for (i = 0; i < num_c_common_reswords; i++) |
| 127 | { |
| 128 | /* If a keyword is disabled, do not enter it into the table |
| 129 | and so create a canonical spelling that isn't a keyword. */ |
| 130 | if (c_common_reswords[i].disable & mask) |
| 131 | { |
| 132 | if (warn_cxx_compat |
| 133 | && (c_common_reswords[i].disable & D_CXXWARN)) |
| 134 | { |
| 135 | id = get_identifier (c_common_reswords[i].word); |
| 136 | C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN); |
| 137 | C_IS_RESERVED_WORD (id) = 1; |
| 138 | } |
| 139 | continue; |
| 140 | } |
| 141 | |
| 142 | id = get_identifier (c_common_reswords[i].word); |
| 143 | C_SET_RID_CODE (id, c_common_reswords[i].rid); |
| 144 | C_IS_RESERVED_WORD (id) = 1; |
| 145 | ridpointers [(int) c_common_reswords[i].rid] = id; |
| 146 | } |
| 147 | |
| 148 | for (i = 0; i < NUM_INT_N_ENTS; i++) |
| 149 | { |
| 150 | /* We always create the symbols but they aren't always supported. */ |
| 151 | char name[50]; |
| 152 | sprintf (name, "__int%d" , int_n_data[i].bitsize); |
| 153 | id = get_identifier (name); |
| 154 | C_SET_RID_CODE (id, RID_FIRST_INT_N + i); |
| 155 | C_IS_RESERVED_WORD (id) = 1; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | /* A parser structure recording information about the state and |
| 160 | context of parsing. Includes lexer information with up to two |
| 161 | tokens of look-ahead; more are not needed for C. */ |
| 162 | struct GTY(()) c_parser { |
| 163 | /* The look-ahead tokens. */ |
| 164 | c_token * GTY((skip)) tokens; |
| 165 | /* Buffer for look-ahead tokens. */ |
| 166 | c_token tokens_buf[4]; |
| 167 | /* How many look-ahead tokens are available (0 - 4, or |
| 168 | more if parsing from pre-lexed tokens). */ |
| 169 | unsigned int tokens_avail; |
| 170 | /* True if a syntax error is being recovered from; false otherwise. |
| 171 | c_parser_error sets this flag. It should clear this flag when |
| 172 | enough tokens have been consumed to recover from the error. */ |
| 173 | BOOL_BITFIELD error : 1; |
| 174 | /* True if we're processing a pragma, and shouldn't automatically |
| 175 | consume CPP_PRAGMA_EOL. */ |
| 176 | BOOL_BITFIELD in_pragma : 1; |
| 177 | /* True if we're parsing the outermost block of an if statement. */ |
| 178 | BOOL_BITFIELD in_if_block : 1; |
| 179 | /* True if we want to lex an untranslated string. */ |
| 180 | BOOL_BITFIELD lex_untranslated_string : 1; |
| 181 | |
| 182 | /* Objective-C specific parser/lexer information. */ |
| 183 | |
| 184 | /* True if we are in a context where the Objective-C "PQ" keywords |
| 185 | are considered keywords. */ |
| 186 | BOOL_BITFIELD objc_pq_context : 1; |
| 187 | /* True if we are parsing a (potential) Objective-C foreach |
| 188 | statement. This is set to true after we parsed 'for (' and while |
| 189 | we wait for 'in' or ';' to decide if it's a standard C for loop or an |
| 190 | Objective-C foreach loop. */ |
| 191 | BOOL_BITFIELD objc_could_be_foreach_context : 1; |
| 192 | /* The following flag is needed to contextualize Objective-C lexical |
| 193 | analysis. In some cases (e.g., 'int NSObject;'), it is |
| 194 | undesirable to bind an identifier to an Objective-C class, even |
| 195 | if a class with that name exists. */ |
| 196 | BOOL_BITFIELD objc_need_raw_identifier : 1; |
| 197 | /* Nonzero if we're processing a __transaction statement. The value |
| 198 | is 1 | TM_STMT_ATTR_*. */ |
| 199 | unsigned int in_transaction : 4; |
| 200 | /* True if we are in a context where the Objective-C "Property attribute" |
| 201 | keywords are valid. */ |
| 202 | BOOL_BITFIELD objc_property_attr_context : 1; |
| 203 | |
| 204 | /* Cilk Plus specific parser/lexer information. */ |
| 205 | |
| 206 | /* Buffer to hold all the tokens from parsing the vector attribute for the |
| 207 | SIMD-enabled functions (formerly known as elemental functions). */ |
| 208 | vec <c_token, va_gc> *cilk_simd_fn_tokens; |
| 209 | }; |
| 210 | |
| 211 | /* Return a pointer to the Nth token in PARSERs tokens_buf. */ |
| 212 | |
| 213 | c_token * |
| 214 | c_parser_tokens_buf (c_parser *parser, unsigned n) |
| 215 | { |
| 216 | return &parser->tokens_buf[n]; |
| 217 | } |
| 218 | |
| 219 | /* Return the error state of PARSER. */ |
| 220 | |
| 221 | bool |
| 222 | c_parser_error (c_parser *parser) |
| 223 | { |
| 224 | return parser->error; |
| 225 | } |
| 226 | |
| 227 | /* Set the error state of PARSER to ERR. */ |
| 228 | |
| 229 | void |
| 230 | c_parser_set_error (c_parser *parser, bool err) |
| 231 | { |
| 232 | parser->error = err; |
| 233 | } |
| 234 | |
| 235 | |
| 236 | /* The actual parser and external interface. ??? Does this need to be |
| 237 | garbage-collected? */ |
| 238 | |
| 239 | static GTY (()) c_parser *the_parser; |
| 240 | |
| 241 | /* Read in and lex a single token, storing it in *TOKEN. */ |
| 242 | |
| 243 | static void |
| 244 | c_lex_one_token (c_parser *parser, c_token *token) |
| 245 | { |
| 246 | timevar_push (TV_LEX); |
| 247 | |
| 248 | token->type = c_lex_with_flags (&token->value, &token->location, |
| 249 | &token->flags, |
| 250 | (parser->lex_untranslated_string |
| 251 | ? C_LEX_STRING_NO_TRANSLATE : 0)); |
| 252 | token->id_kind = C_ID_NONE; |
| 253 | token->keyword = RID_MAX; |
| 254 | token->pragma_kind = PRAGMA_NONE; |
| 255 | |
| 256 | switch (token->type) |
| 257 | { |
| 258 | case CPP_NAME: |
| 259 | { |
| 260 | tree decl; |
| 261 | |
| 262 | bool objc_force_identifier = parser->objc_need_raw_identifier; |
| 263 | if (c_dialect_objc ()) |
| 264 | parser->objc_need_raw_identifier = false; |
| 265 | |
| 266 | if (C_IS_RESERVED_WORD (token->value)) |
| 267 | { |
| 268 | enum rid rid_code = C_RID_CODE (token->value); |
| 269 | |
| 270 | if (rid_code == RID_CXX_COMPAT_WARN) |
| 271 | { |
| 272 | warning_at (token->location, |
| 273 | OPT_Wc___compat, |
| 274 | "identifier %qE conflicts with C++ keyword" , |
| 275 | token->value); |
| 276 | } |
| 277 | else if (rid_code >= RID_FIRST_ADDR_SPACE |
| 278 | && rid_code <= RID_LAST_ADDR_SPACE) |
| 279 | { |
| 280 | addr_space_t as; |
| 281 | as = (addr_space_t) (rid_code - RID_FIRST_ADDR_SPACE); |
| 282 | targetm.addr_space.diagnose_usage (as, token->location); |
| 283 | token->id_kind = C_ID_ADDRSPACE; |
| 284 | token->keyword = rid_code; |
| 285 | break; |
| 286 | } |
| 287 | else if (c_dialect_objc () && OBJC_IS_PQ_KEYWORD (rid_code)) |
| 288 | { |
| 289 | /* We found an Objective-C "pq" keyword (in, out, |
| 290 | inout, bycopy, byref, oneway). They need special |
| 291 | care because the interpretation depends on the |
| 292 | context. */ |
| 293 | if (parser->objc_pq_context) |
| 294 | { |
| 295 | token->type = CPP_KEYWORD; |
| 296 | token->keyword = rid_code; |
| 297 | break; |
| 298 | } |
| 299 | else if (parser->objc_could_be_foreach_context |
| 300 | && rid_code == RID_IN) |
| 301 | { |
| 302 | /* We are in Objective-C, inside a (potential) |
| 303 | foreach context (which means after having |
| 304 | parsed 'for (', but before having parsed ';'), |
| 305 | and we found 'in'. We consider it the keyword |
| 306 | which terminates the declaration at the |
| 307 | beginning of a foreach-statement. Note that |
| 308 | this means you can't use 'in' for anything else |
| 309 | in that context; in particular, in Objective-C |
| 310 | you can't use 'in' as the name of the running |
| 311 | variable in a C for loop. We could potentially |
| 312 | try to add code here to disambiguate, but it |
| 313 | seems a reasonable limitation. */ |
| 314 | token->type = CPP_KEYWORD; |
| 315 | token->keyword = rid_code; |
| 316 | break; |
| 317 | } |
| 318 | /* Else, "pq" keywords outside of the "pq" context are |
| 319 | not keywords, and we fall through to the code for |
| 320 | normal tokens. */ |
| 321 | } |
| 322 | else if (c_dialect_objc () && OBJC_IS_PATTR_KEYWORD (rid_code)) |
| 323 | { |
| 324 | /* We found an Objective-C "property attribute" |
| 325 | keyword (getter, setter, readonly, etc). These are |
| 326 | only valid in the property context. */ |
| 327 | if (parser->objc_property_attr_context) |
| 328 | { |
| 329 | token->type = CPP_KEYWORD; |
| 330 | token->keyword = rid_code; |
| 331 | break; |
| 332 | } |
| 333 | /* Else they are not special keywords. |
| 334 | */ |
| 335 | } |
| 336 | else if (c_dialect_objc () |
| 337 | && (OBJC_IS_AT_KEYWORD (rid_code) |
| 338 | || OBJC_IS_CXX_KEYWORD (rid_code))) |
| 339 | { |
| 340 | /* We found one of the Objective-C "@" keywords (defs, |
| 341 | selector, synchronized, etc) or one of the |
| 342 | Objective-C "cxx" keywords (class, private, |
| 343 | protected, public, try, catch, throw) without a |
| 344 | preceding '@' sign. Do nothing and fall through to |
| 345 | the code for normal tokens (in C++ we would still |
| 346 | consider the CXX ones keywords, but not in C). */ |
| 347 | ; |
| 348 | } |
| 349 | else |
| 350 | { |
| 351 | token->type = CPP_KEYWORD; |
| 352 | token->keyword = rid_code; |
| 353 | break; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | decl = lookup_name (token->value); |
| 358 | if (decl) |
| 359 | { |
| 360 | if (TREE_CODE (decl) == TYPE_DECL) |
| 361 | { |
| 362 | token->id_kind = C_ID_TYPENAME; |
| 363 | break; |
| 364 | } |
| 365 | } |
| 366 | else if (c_dialect_objc ()) |
| 367 | { |
| 368 | tree objc_interface_decl = objc_is_class_name (token->value); |
| 369 | /* Objective-C class names are in the same namespace as |
| 370 | variables and typedefs, and hence are shadowed by local |
| 371 | declarations. */ |
| 372 | if (objc_interface_decl |
| 373 | && (!objc_force_identifier || global_bindings_p ())) |
| 374 | { |
| 375 | token->value = objc_interface_decl; |
| 376 | token->id_kind = C_ID_CLASSNAME; |
| 377 | break; |
| 378 | } |
| 379 | } |
| 380 | token->id_kind = C_ID_ID; |
| 381 | } |
| 382 | break; |
| 383 | case CPP_AT_NAME: |
| 384 | /* This only happens in Objective-C; it must be a keyword. */ |
| 385 | token->type = CPP_KEYWORD; |
| 386 | switch (C_RID_CODE (token->value)) |
| 387 | { |
| 388 | /* Replace 'class' with '@class', 'private' with '@private', |
| 389 | etc. This prevents confusion with the C++ keyword |
| 390 | 'class', and makes the tokens consistent with other |
| 391 | Objective-C 'AT' keywords. For example '@class' is |
| 392 | reported as RID_AT_CLASS which is consistent with |
| 393 | '@synchronized', which is reported as |
| 394 | RID_AT_SYNCHRONIZED. |
| 395 | */ |
| 396 | case RID_CLASS: token->keyword = RID_AT_CLASS; break; |
| 397 | case RID_PRIVATE: token->keyword = RID_AT_PRIVATE; break; |
| 398 | case RID_PROTECTED: token->keyword = RID_AT_PROTECTED; break; |
| 399 | case RID_PUBLIC: token->keyword = RID_AT_PUBLIC; break; |
| 400 | case RID_THROW: token->keyword = RID_AT_THROW; break; |
| 401 | case RID_TRY: token->keyword = RID_AT_TRY; break; |
| 402 | case RID_CATCH: token->keyword = RID_AT_CATCH; break; |
| 403 | case RID_SYNCHRONIZED: token->keyword = RID_AT_SYNCHRONIZED; break; |
| 404 | default: token->keyword = C_RID_CODE (token->value); |
| 405 | } |
| 406 | break; |
| 407 | case CPP_COLON: |
| 408 | case CPP_COMMA: |
| 409 | case CPP_CLOSE_PAREN: |
| 410 | case CPP_SEMICOLON: |
| 411 | /* These tokens may affect the interpretation of any identifiers |
| 412 | following, if doing Objective-C. */ |
| 413 | if (c_dialect_objc ()) |
| 414 | parser->objc_need_raw_identifier = false; |
| 415 | break; |
| 416 | case CPP_PRAGMA: |
| 417 | /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */ |
| 418 | token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value); |
| 419 | token->value = NULL; |
| 420 | break; |
| 421 | default: |
| 422 | break; |
| 423 | } |
| 424 | timevar_pop (TV_LEX); |
| 425 | } |
| 426 | |
| 427 | /* Return a pointer to the next token from PARSER, reading it in if |
| 428 | necessary. */ |
| 429 | |
| 430 | c_token * |
| 431 | c_parser_peek_token (c_parser *parser) |
| 432 | { |
| 433 | if (parser->tokens_avail == 0) |
| 434 | { |
| 435 | c_lex_one_token (parser, &parser->tokens[0]); |
| 436 | parser->tokens_avail = 1; |
| 437 | } |
| 438 | return &parser->tokens[0]; |
| 439 | } |
| 440 | |
| 441 | /* Return a pointer to the next-but-one token from PARSER, reading it |
| 442 | in if necessary. The next token is already read in. */ |
| 443 | |
| 444 | c_token * |
| 445 | c_parser_peek_2nd_token (c_parser *parser) |
| 446 | { |
| 447 | if (parser->tokens_avail >= 2) |
| 448 | return &parser->tokens[1]; |
| 449 | gcc_assert (parser->tokens_avail == 1); |
| 450 | gcc_assert (parser->tokens[0].type != CPP_EOF); |
| 451 | gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL); |
| 452 | c_lex_one_token (parser, &parser->tokens[1]); |
| 453 | parser->tokens_avail = 2; |
| 454 | return &parser->tokens[1]; |
| 455 | } |
| 456 | |
| 457 | /* Return a pointer to the Nth token from PARSER, reading it |
| 458 | in if necessary. The N-1th token is already read in. */ |
| 459 | |
| 460 | c_token * |
| 461 | c_parser_peek_nth_token (c_parser *parser, unsigned int n) |
| 462 | { |
| 463 | /* N is 1-based, not zero-based. */ |
| 464 | gcc_assert (n > 0); |
| 465 | |
| 466 | if (parser->tokens_avail >= n) |
| 467 | return &parser->tokens[n - 1]; |
| 468 | gcc_assert (parser->tokens_avail == n - 1); |
| 469 | c_lex_one_token (parser, &parser->tokens[n - 1]); |
| 470 | parser->tokens_avail = n; |
| 471 | return &parser->tokens[n - 1]; |
| 472 | } |
| 473 | |
| 474 | bool |
| 475 | c_keyword_starts_typename (enum rid keyword) |
| 476 | { |
| 477 | switch (keyword) |
| 478 | { |
| 479 | case RID_UNSIGNED: |
| 480 | case RID_LONG: |
| 481 | case RID_SHORT: |
| 482 | case RID_SIGNED: |
| 483 | case RID_COMPLEX: |
| 484 | case RID_INT: |
| 485 | case RID_CHAR: |
| 486 | case RID_FLOAT: |
| 487 | case RID_DOUBLE: |
| 488 | case RID_VOID: |
| 489 | case RID_DFLOAT32: |
| 490 | case RID_DFLOAT64: |
| 491 | case RID_DFLOAT128: |
| 492 | CASE_RID_FLOATN_NX: |
| 493 | case RID_BOOL: |
| 494 | case RID_ENUM: |
| 495 | case RID_STRUCT: |
| 496 | case RID_UNION: |
| 497 | case RID_TYPEOF: |
| 498 | case RID_CONST: |
| 499 | case RID_ATOMIC: |
| 500 | case RID_VOLATILE: |
| 501 | case RID_RESTRICT: |
| 502 | case RID_ATTRIBUTE: |
| 503 | case RID_FRACT: |
| 504 | case RID_ACCUM: |
| 505 | case RID_SAT: |
| 506 | case RID_AUTO_TYPE: |
| 507 | return true; |
| 508 | default: |
| 509 | if (keyword >= RID_FIRST_INT_N |
| 510 | && keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS |
| 511 | && int_n_enabled_p[keyword - RID_FIRST_INT_N]) |
| 512 | return true; |
| 513 | return false; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | /* Return true if TOKEN can start a type name, |
| 518 | false otherwise. */ |
| 519 | bool |
| 520 | c_token_starts_typename (c_token *token) |
| 521 | { |
| 522 | switch (token->type) |
| 523 | { |
| 524 | case CPP_NAME: |
| 525 | switch (token->id_kind) |
| 526 | { |
| 527 | case C_ID_ID: |
| 528 | return false; |
| 529 | case C_ID_ADDRSPACE: |
| 530 | return true; |
| 531 | case C_ID_TYPENAME: |
| 532 | return true; |
| 533 | case C_ID_CLASSNAME: |
| 534 | gcc_assert (c_dialect_objc ()); |
| 535 | return true; |
| 536 | default: |
| 537 | gcc_unreachable (); |
| 538 | } |
| 539 | case CPP_KEYWORD: |
| 540 | return c_keyword_starts_typename (token->keyword); |
| 541 | case CPP_LESS: |
| 542 | if (c_dialect_objc ()) |
| 543 | return true; |
| 544 | return false; |
| 545 | default: |
| 546 | return false; |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | /* Return true if the next token from PARSER can start a type name, |
| 551 | false otherwise. LA specifies how to do lookahead in order to |
| 552 | detect unknown type names. If unsure, pick CLA_PREFER_ID. */ |
| 553 | |
| 554 | static inline bool |
| 555 | c_parser_next_tokens_start_typename (c_parser *parser, enum c_lookahead_kind la) |
| 556 | { |
| 557 | c_token *token = c_parser_peek_token (parser); |
| 558 | if (c_token_starts_typename (token)) |
| 559 | return true; |
| 560 | |
| 561 | /* Try a bit harder to detect an unknown typename. */ |
| 562 | if (la != cla_prefer_id |
| 563 | && token->type == CPP_NAME |
| 564 | && token->id_kind == C_ID_ID |
| 565 | |
| 566 | /* Do not try too hard when we could have "object in array". */ |
| 567 | && !parser->objc_could_be_foreach_context |
| 568 | |
| 569 | && (la == cla_prefer_type |
| 570 | || c_parser_peek_2nd_token (parser)->type == CPP_NAME |
| 571 | || c_parser_peek_2nd_token (parser)->type == CPP_MULT) |
| 572 | |
| 573 | /* Only unknown identifiers. */ |
| 574 | && !lookup_name (token->value)) |
| 575 | return true; |
| 576 | |
| 577 | return false; |
| 578 | } |
| 579 | |
| 580 | /* Return true if TOKEN is a type qualifier, false otherwise. */ |
| 581 | static bool |
| 582 | c_token_is_qualifier (c_token *token) |
| 583 | { |
| 584 | switch (token->type) |
| 585 | { |
| 586 | case CPP_NAME: |
| 587 | switch (token->id_kind) |
| 588 | { |
| 589 | case C_ID_ADDRSPACE: |
| 590 | return true; |
| 591 | default: |
| 592 | return false; |
| 593 | } |
| 594 | case CPP_KEYWORD: |
| 595 | switch (token->keyword) |
| 596 | { |
| 597 | case RID_CONST: |
| 598 | case RID_VOLATILE: |
| 599 | case RID_RESTRICT: |
| 600 | case RID_ATTRIBUTE: |
| 601 | case RID_ATOMIC: |
| 602 | return true; |
| 603 | default: |
| 604 | return false; |
| 605 | } |
| 606 | case CPP_LESS: |
| 607 | return false; |
| 608 | default: |
| 609 | gcc_unreachable (); |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | /* Return true if the next token from PARSER is a type qualifier, |
| 614 | false otherwise. */ |
| 615 | static inline bool |
| 616 | c_parser_next_token_is_qualifier (c_parser *parser) |
| 617 | { |
| 618 | c_token *token = c_parser_peek_token (parser); |
| 619 | return c_token_is_qualifier (token); |
| 620 | } |
| 621 | |
| 622 | /* Return true if TOKEN can start declaration specifiers, false |
| 623 | otherwise. */ |
| 624 | static bool |
| 625 | c_token_starts_declspecs (c_token *token) |
| 626 | { |
| 627 | switch (token->type) |
| 628 | { |
| 629 | case CPP_NAME: |
| 630 | switch (token->id_kind) |
| 631 | { |
| 632 | case C_ID_ID: |
| 633 | return false; |
| 634 | case C_ID_ADDRSPACE: |
| 635 | return true; |
| 636 | case C_ID_TYPENAME: |
| 637 | return true; |
| 638 | case C_ID_CLASSNAME: |
| 639 | gcc_assert (c_dialect_objc ()); |
| 640 | return true; |
| 641 | default: |
| 642 | gcc_unreachable (); |
| 643 | } |
| 644 | case CPP_KEYWORD: |
| 645 | switch (token->keyword) |
| 646 | { |
| 647 | case RID_STATIC: |
| 648 | case RID_EXTERN: |
| 649 | case RID_REGISTER: |
| 650 | case RID_TYPEDEF: |
| 651 | case RID_INLINE: |
| 652 | case RID_NORETURN: |
| 653 | case RID_AUTO: |
| 654 | case RID_THREAD: |
| 655 | case RID_UNSIGNED: |
| 656 | case RID_LONG: |
| 657 | case RID_SHORT: |
| 658 | case RID_SIGNED: |
| 659 | case RID_COMPLEX: |
| 660 | case RID_INT: |
| 661 | case RID_CHAR: |
| 662 | case RID_FLOAT: |
| 663 | case RID_DOUBLE: |
| 664 | case RID_VOID: |
| 665 | case RID_DFLOAT32: |
| 666 | case RID_DFLOAT64: |
| 667 | case RID_DFLOAT128: |
| 668 | CASE_RID_FLOATN_NX: |
| 669 | case RID_BOOL: |
| 670 | case RID_ENUM: |
| 671 | case RID_STRUCT: |
| 672 | case RID_UNION: |
| 673 | case RID_TYPEOF: |
| 674 | case RID_CONST: |
| 675 | case RID_VOLATILE: |
| 676 | case RID_RESTRICT: |
| 677 | case RID_ATTRIBUTE: |
| 678 | case RID_FRACT: |
| 679 | case RID_ACCUM: |
| 680 | case RID_SAT: |
| 681 | case RID_ALIGNAS: |
| 682 | case RID_ATOMIC: |
| 683 | case RID_AUTO_TYPE: |
| 684 | return true; |
| 685 | default: |
| 686 | if (token->keyword >= RID_FIRST_INT_N |
| 687 | && token->keyword < RID_FIRST_INT_N + NUM_INT_N_ENTS |
| 688 | && int_n_enabled_p[token->keyword - RID_FIRST_INT_N]) |
| 689 | return true; |
| 690 | return false; |
| 691 | } |
| 692 | case CPP_LESS: |
| 693 | if (c_dialect_objc ()) |
| 694 | return true; |
| 695 | return false; |
| 696 | default: |
| 697 | return false; |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | |
| 702 | /* Return true if TOKEN can start declaration specifiers or a static |
| 703 | assertion, false otherwise. */ |
| 704 | static bool |
| 705 | c_token_starts_declaration (c_token *token) |
| 706 | { |
| 707 | if (c_token_starts_declspecs (token) |
| 708 | || token->keyword == RID_STATIC_ASSERT) |
| 709 | return true; |
| 710 | else |
| 711 | return false; |
| 712 | } |
| 713 | |
| 714 | /* Return true if the next token from PARSER can start declaration |
| 715 | specifiers, false otherwise. */ |
| 716 | bool |
| 717 | c_parser_next_token_starts_declspecs (c_parser *parser) |
| 718 | { |
| 719 | c_token *token = c_parser_peek_token (parser); |
| 720 | |
| 721 | /* In Objective-C, a classname normally starts a declspecs unless it |
| 722 | is immediately followed by a dot. In that case, it is the |
| 723 | Objective-C 2.0 "dot-syntax" for class objects, ie, calls the |
| 724 | setter/getter on the class. c_token_starts_declspecs() can't |
| 725 | differentiate between the two cases because it only checks the |
| 726 | current token, so we have a special check here. */ |
| 727 | if (c_dialect_objc () |
| 728 | && token->type == CPP_NAME |
| 729 | && token->id_kind == C_ID_CLASSNAME |
| 730 | && c_parser_peek_2nd_token (parser)->type == CPP_DOT) |
| 731 | return false; |
| 732 | |
| 733 | return c_token_starts_declspecs (token); |
| 734 | } |
| 735 | |
| 736 | /* Return true if the next tokens from PARSER can start declaration |
| 737 | specifiers or a static assertion, false otherwise. */ |
| 738 | bool |
| 739 | c_parser_next_tokens_start_declaration (c_parser *parser) |
| 740 | { |
| 741 | c_token *token = c_parser_peek_token (parser); |
| 742 | |
| 743 | /* Same as above. */ |
| 744 | if (c_dialect_objc () |
| 745 | && token->type == CPP_NAME |
| 746 | && token->id_kind == C_ID_CLASSNAME |
| 747 | && c_parser_peek_2nd_token (parser)->type == CPP_DOT) |
| 748 | return false; |
| 749 | |
| 750 | /* Labels do not start declarations. */ |
| 751 | if (token->type == CPP_NAME |
| 752 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 753 | return false; |
| 754 | |
| 755 | if (c_token_starts_declaration (token)) |
| 756 | return true; |
| 757 | |
| 758 | if (c_parser_next_tokens_start_typename (parser, cla_nonabstract_decl)) |
| 759 | return true; |
| 760 | |
| 761 | return false; |
| 762 | } |
| 763 | |
| 764 | /* Consume the next token from PARSER. */ |
| 765 | |
| 766 | void |
| 767 | c_parser_consume_token (c_parser *parser) |
| 768 | { |
| 769 | gcc_assert (parser->tokens_avail >= 1); |
| 770 | gcc_assert (parser->tokens[0].type != CPP_EOF); |
| 771 | gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL); |
| 772 | gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA); |
| 773 | if (parser->tokens != &parser->tokens_buf[0]) |
| 774 | parser->tokens++; |
| 775 | else if (parser->tokens_avail == 2) |
| 776 | parser->tokens[0] = parser->tokens[1]; |
| 777 | parser->tokens_avail--; |
| 778 | } |
| 779 | |
| 780 | /* Expect the current token to be a #pragma. Consume it and remember |
| 781 | that we've begun parsing a pragma. */ |
| 782 | |
| 783 | static void |
| 784 | c_parser_consume_pragma (c_parser *parser) |
| 785 | { |
| 786 | gcc_assert (!parser->in_pragma); |
| 787 | gcc_assert (parser->tokens_avail >= 1); |
| 788 | gcc_assert (parser->tokens[0].type == CPP_PRAGMA); |
| 789 | if (parser->tokens != &parser->tokens_buf[0]) |
| 790 | parser->tokens++; |
| 791 | else if (parser->tokens_avail == 2) |
| 792 | parser->tokens[0] = parser->tokens[1]; |
| 793 | parser->tokens_avail--; |
| 794 | parser->in_pragma = true; |
| 795 | } |
| 796 | |
| 797 | /* Update the global input_location from TOKEN. */ |
| 798 | static inline void |
| 799 | c_parser_set_source_position_from_token (c_token *token) |
| 800 | { |
| 801 | if (token->type != CPP_EOF) |
| 802 | { |
| 803 | input_location = token->location; |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | /* Helper function for c_parser_error. |
| 808 | Having peeked a token of kind TOK1_KIND that might signify |
| 809 | a conflict marker, peek successor tokens to determine |
| 810 | if we actually do have a conflict marker. |
| 811 | Specifically, we consider a run of 7 '<', '=' or '>' characters |
| 812 | at the start of a line as a conflict marker. |
| 813 | These come through the lexer as three pairs and a single, |
| 814 | e.g. three CPP_LSHIFT ("<<") and a CPP_LESS ('<'). |
| 815 | If it returns true, *OUT_LOC is written to with the location/range |
| 816 | of the marker. */ |
| 817 | |
| 818 | static bool |
| 819 | c_parser_peek_conflict_marker (c_parser *parser, enum cpp_ttype tok1_kind, |
| 820 | location_t *out_loc) |
| 821 | { |
| 822 | c_token *token2 = c_parser_peek_2nd_token (parser); |
| 823 | if (token2->type != tok1_kind) |
| 824 | return false; |
| 825 | c_token *token3 = c_parser_peek_nth_token (parser, 3); |
| 826 | if (token3->type != tok1_kind) |
| 827 | return false; |
| 828 | c_token *token4 = c_parser_peek_nth_token (parser, 4); |
| 829 | if (token4->type != conflict_marker_get_final_tok_kind (tok1_kind)) |
| 830 | return false; |
| 831 | |
| 832 | /* It must be at the start of the line. */ |
| 833 | location_t start_loc = c_parser_peek_token (parser)->location; |
| 834 | if (LOCATION_COLUMN (start_loc) != 1) |
| 835 | return false; |
| 836 | |
| 837 | /* We have a conflict marker. Construct a location of the form: |
| 838 | <<<<<<< |
| 839 | ^~~~~~~ |
| 840 | with start == caret, finishing at the end of the marker. */ |
| 841 | location_t finish_loc = get_finish (token4->location); |
| 842 | *out_loc = make_location (start_loc, start_loc, finish_loc); |
| 843 | |
| 844 | return true; |
| 845 | } |
| 846 | |
| 847 | /* Issue a diagnostic of the form |
| 848 | FILE:LINE: MESSAGE before TOKEN |
| 849 | where TOKEN is the next token in the input stream of PARSER. |
| 850 | MESSAGE (specified by the caller) is usually of the form "expected |
| 851 | OTHER-TOKEN". |
| 852 | |
| 853 | Do not issue a diagnostic if still recovering from an error. |
| 854 | |
| 855 | ??? This is taken from the C++ parser, but building up messages in |
| 856 | this way is not i18n-friendly and some other approach should be |
| 857 | used. */ |
| 858 | |
| 859 | void |
| 860 | c_parser_error (c_parser *parser, const char *gmsgid) |
| 861 | { |
| 862 | c_token *token = c_parser_peek_token (parser); |
| 863 | if (parser->error) |
| 864 | return; |
| 865 | parser->error = true; |
| 866 | if (!gmsgid) |
| 867 | return; |
| 868 | |
| 869 | /* If this is actually a conflict marker, report it as such. */ |
| 870 | if (token->type == CPP_LSHIFT |
| 871 | || token->type == CPP_RSHIFT |
| 872 | || token->type == CPP_EQ_EQ) |
| 873 | { |
| 874 | location_t loc; |
| 875 | if (c_parser_peek_conflict_marker (parser, token->type, &loc)) |
| 876 | { |
| 877 | error_at (loc, "version control conflict marker in file" ); |
| 878 | return; |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | /* This diagnostic makes more sense if it is tagged to the line of |
| 883 | the token we just peeked at. */ |
| 884 | c_parser_set_source_position_from_token (token); |
| 885 | c_parse_error (gmsgid, |
| 886 | /* Because c_parse_error does not understand |
| 887 | CPP_KEYWORD, keywords are treated like |
| 888 | identifiers. */ |
| 889 | (token->type == CPP_KEYWORD ? CPP_NAME : token->type), |
| 890 | /* ??? The C parser does not save the cpp flags of a |
| 891 | token, we need to pass 0 here and we will not get |
| 892 | the source spelling of some tokens but rather the |
| 893 | canonical spelling. */ |
| 894 | token->value, /*flags=*/0); |
| 895 | } |
| 896 | |
| 897 | /* If the next token is of the indicated TYPE, consume it. Otherwise, |
| 898 | issue the error MSGID. If MSGID is NULL then a message has already |
| 899 | been produced and no message will be produced this time. Returns |
| 900 | true if found, false otherwise. */ |
| 901 | |
| 902 | bool |
| 903 | c_parser_require (c_parser *parser, |
| 904 | enum cpp_ttype type, |
| 905 | const char *msgid) |
| 906 | { |
| 907 | if (c_parser_next_token_is (parser, type)) |
| 908 | { |
| 909 | c_parser_consume_token (parser); |
| 910 | return true; |
| 911 | } |
| 912 | else |
| 913 | { |
| 914 | c_parser_error (parser, msgid); |
| 915 | return false; |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | /* If the next token is the indicated keyword, consume it. Otherwise, |
| 920 | issue the error MSGID. Returns true if found, false otherwise. */ |
| 921 | |
| 922 | static bool |
| 923 | c_parser_require_keyword (c_parser *parser, |
| 924 | enum rid keyword, |
| 925 | const char *msgid) |
| 926 | { |
| 927 | if (c_parser_next_token_is_keyword (parser, keyword)) |
| 928 | { |
| 929 | c_parser_consume_token (parser); |
| 930 | return true; |
| 931 | } |
| 932 | else |
| 933 | { |
| 934 | c_parser_error (parser, msgid); |
| 935 | return false; |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | /* Like c_parser_require, except that tokens will be skipped until the |
| 940 | desired token is found. An error message is still produced if the |
| 941 | next token is not as expected. If MSGID is NULL then a message has |
| 942 | already been produced and no message will be produced this |
| 943 | time. */ |
| 944 | |
| 945 | void |
| 946 | c_parser_skip_until_found (c_parser *parser, |
| 947 | enum cpp_ttype type, |
| 948 | const char *msgid) |
| 949 | { |
| 950 | unsigned nesting_depth = 0; |
| 951 | |
| 952 | if (c_parser_require (parser, type, msgid)) |
| 953 | return; |
| 954 | |
| 955 | /* Skip tokens until the desired token is found. */ |
| 956 | while (true) |
| 957 | { |
| 958 | /* Peek at the next token. */ |
| 959 | c_token *token = c_parser_peek_token (parser); |
| 960 | /* If we've reached the token we want, consume it and stop. */ |
| 961 | if (token->type == type && !nesting_depth) |
| 962 | { |
| 963 | c_parser_consume_token (parser); |
| 964 | break; |
| 965 | } |
| 966 | |
| 967 | /* If we've run out of tokens, stop. */ |
| 968 | if (token->type == CPP_EOF) |
| 969 | return; |
| 970 | if (token->type == CPP_PRAGMA_EOL && parser->in_pragma) |
| 971 | return; |
| 972 | if (token->type == CPP_OPEN_BRACE |
| 973 | || token->type == CPP_OPEN_PAREN |
| 974 | || token->type == CPP_OPEN_SQUARE) |
| 975 | ++nesting_depth; |
| 976 | else if (token->type == CPP_CLOSE_BRACE |
| 977 | || token->type == CPP_CLOSE_PAREN |
| 978 | || token->type == CPP_CLOSE_SQUARE) |
| 979 | { |
| 980 | if (nesting_depth-- == 0) |
| 981 | break; |
| 982 | } |
| 983 | /* Consume this token. */ |
| 984 | c_parser_consume_token (parser); |
| 985 | } |
| 986 | parser->error = false; |
| 987 | } |
| 988 | |
| 989 | /* Skip tokens until the end of a parameter is found, but do not |
| 990 | consume the comma, semicolon or closing delimiter. */ |
| 991 | |
| 992 | static void |
| 993 | c_parser_skip_to_end_of_parameter (c_parser *parser) |
| 994 | { |
| 995 | unsigned nesting_depth = 0; |
| 996 | |
| 997 | while (true) |
| 998 | { |
| 999 | c_token *token = c_parser_peek_token (parser); |
| 1000 | if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON) |
| 1001 | && !nesting_depth) |
| 1002 | break; |
| 1003 | /* If we've run out of tokens, stop. */ |
| 1004 | if (token->type == CPP_EOF) |
| 1005 | return; |
| 1006 | if (token->type == CPP_PRAGMA_EOL && parser->in_pragma) |
| 1007 | return; |
| 1008 | if (token->type == CPP_OPEN_BRACE |
| 1009 | || token->type == CPP_OPEN_PAREN |
| 1010 | || token->type == CPP_OPEN_SQUARE) |
| 1011 | ++nesting_depth; |
| 1012 | else if (token->type == CPP_CLOSE_BRACE |
| 1013 | || token->type == CPP_CLOSE_PAREN |
| 1014 | || token->type == CPP_CLOSE_SQUARE) |
| 1015 | { |
| 1016 | if (nesting_depth-- == 0) |
| 1017 | break; |
| 1018 | } |
| 1019 | /* Consume this token. */ |
| 1020 | c_parser_consume_token (parser); |
| 1021 | } |
| 1022 | parser->error = false; |
| 1023 | } |
| 1024 | |
| 1025 | /* Expect to be at the end of the pragma directive and consume an |
| 1026 | end of line marker. */ |
| 1027 | |
| 1028 | static void |
| 1029 | c_parser_skip_to_pragma_eol (c_parser *parser, bool error_if_not_eol = true) |
| 1030 | { |
| 1031 | gcc_assert (parser->in_pragma); |
| 1032 | parser->in_pragma = false; |
| 1033 | |
| 1034 | if (error_if_not_eol && c_parser_peek_token (parser)->type != CPP_PRAGMA_EOL) |
| 1035 | c_parser_error (parser, "expected end of line" ); |
| 1036 | |
| 1037 | cpp_ttype token_type; |
| 1038 | do |
| 1039 | { |
| 1040 | c_token *token = c_parser_peek_token (parser); |
| 1041 | token_type = token->type; |
| 1042 | if (token_type == CPP_EOF) |
| 1043 | break; |
| 1044 | c_parser_consume_token (parser); |
| 1045 | } |
| 1046 | while (token_type != CPP_PRAGMA_EOL); |
| 1047 | |
| 1048 | parser->error = false; |
| 1049 | } |
| 1050 | |
| 1051 | /* Skip tokens until we have consumed an entire block, or until we |
| 1052 | have consumed a non-nested ';'. */ |
| 1053 | |
| 1054 | static void |
| 1055 | c_parser_skip_to_end_of_block_or_statement (c_parser *parser) |
| 1056 | { |
| 1057 | unsigned nesting_depth = 0; |
| 1058 | bool save_error = parser->error; |
| 1059 | |
| 1060 | while (true) |
| 1061 | { |
| 1062 | c_token *token; |
| 1063 | |
| 1064 | /* Peek at the next token. */ |
| 1065 | token = c_parser_peek_token (parser); |
| 1066 | |
| 1067 | switch (token->type) |
| 1068 | { |
| 1069 | case CPP_EOF: |
| 1070 | return; |
| 1071 | |
| 1072 | case CPP_PRAGMA_EOL: |
| 1073 | if (parser->in_pragma) |
| 1074 | return; |
| 1075 | break; |
| 1076 | |
| 1077 | case CPP_SEMICOLON: |
| 1078 | /* If the next token is a ';', we have reached the |
| 1079 | end of the statement. */ |
| 1080 | if (!nesting_depth) |
| 1081 | { |
| 1082 | /* Consume the ';'. */ |
| 1083 | c_parser_consume_token (parser); |
| 1084 | goto finished; |
| 1085 | } |
| 1086 | break; |
| 1087 | |
| 1088 | case CPP_CLOSE_BRACE: |
| 1089 | /* If the next token is a non-nested '}', then we have |
| 1090 | reached the end of the current block. */ |
| 1091 | if (nesting_depth == 0 || --nesting_depth == 0) |
| 1092 | { |
| 1093 | c_parser_consume_token (parser); |
| 1094 | goto finished; |
| 1095 | } |
| 1096 | break; |
| 1097 | |
| 1098 | case CPP_OPEN_BRACE: |
| 1099 | /* If it the next token is a '{', then we are entering a new |
| 1100 | block. Consume the entire block. */ |
| 1101 | ++nesting_depth; |
| 1102 | break; |
| 1103 | |
| 1104 | case CPP_PRAGMA: |
| 1105 | /* If we see a pragma, consume the whole thing at once. We |
| 1106 | have some safeguards against consuming pragmas willy-nilly. |
| 1107 | Normally, we'd expect to be here with parser->error set, |
| 1108 | which disables these safeguards. But it's possible to get |
| 1109 | here for secondary error recovery, after parser->error has |
| 1110 | been cleared. */ |
| 1111 | c_parser_consume_pragma (parser); |
| 1112 | c_parser_skip_to_pragma_eol (parser); |
| 1113 | parser->error = save_error; |
| 1114 | continue; |
| 1115 | |
| 1116 | default: |
| 1117 | break; |
| 1118 | } |
| 1119 | |
| 1120 | c_parser_consume_token (parser); |
| 1121 | } |
| 1122 | |
| 1123 | finished: |
| 1124 | parser->error = false; |
| 1125 | } |
| 1126 | |
| 1127 | /* CPP's options (initialized by c-opts.c). */ |
| 1128 | extern cpp_options *cpp_opts; |
| 1129 | |
| 1130 | /* Save the warning flags which are controlled by __extension__. */ |
| 1131 | |
| 1132 | static inline int |
| 1133 | disable_extension_diagnostics (void) |
| 1134 | { |
| 1135 | int ret = (pedantic |
| 1136 | | (warn_pointer_arith << 1) |
| 1137 | | (warn_traditional << 2) |
| 1138 | | (flag_iso << 3) |
| 1139 | | (warn_long_long << 4) |
| 1140 | | (warn_cxx_compat << 5) |
| 1141 | | (warn_overlength_strings << 6) |
| 1142 | /* warn_c90_c99_compat has three states: -1/0/1, so we must |
| 1143 | play tricks to properly restore it. */ |
| 1144 | | ((warn_c90_c99_compat == 1) << 7) |
| 1145 | | ((warn_c90_c99_compat == -1) << 8) |
| 1146 | /* Similarly for warn_c99_c11_compat. */ |
| 1147 | | ((warn_c99_c11_compat == 1) << 9) |
| 1148 | | ((warn_c99_c11_compat == -1) << 10) |
| 1149 | ); |
| 1150 | cpp_opts->cpp_pedantic = pedantic = 0; |
| 1151 | warn_pointer_arith = 0; |
| 1152 | cpp_opts->cpp_warn_traditional = warn_traditional = 0; |
| 1153 | flag_iso = 0; |
| 1154 | cpp_opts->cpp_warn_long_long = warn_long_long = 0; |
| 1155 | warn_cxx_compat = 0; |
| 1156 | warn_overlength_strings = 0; |
| 1157 | warn_c90_c99_compat = 0; |
| 1158 | warn_c99_c11_compat = 0; |
| 1159 | return ret; |
| 1160 | } |
| 1161 | |
| 1162 | /* Restore the warning flags which are controlled by __extension__. |
| 1163 | FLAGS is the return value from disable_extension_diagnostics. */ |
| 1164 | |
| 1165 | static inline void |
| 1166 | restore_extension_diagnostics (int flags) |
| 1167 | { |
| 1168 | cpp_opts->cpp_pedantic = pedantic = flags & 1; |
| 1169 | warn_pointer_arith = (flags >> 1) & 1; |
| 1170 | cpp_opts->cpp_warn_traditional = warn_traditional = (flags >> 2) & 1; |
| 1171 | flag_iso = (flags >> 3) & 1; |
| 1172 | cpp_opts->cpp_warn_long_long = warn_long_long = (flags >> 4) & 1; |
| 1173 | warn_cxx_compat = (flags >> 5) & 1; |
| 1174 | warn_overlength_strings = (flags >> 6) & 1; |
| 1175 | /* See above for why is this needed. */ |
| 1176 | warn_c90_c99_compat = (flags >> 7) & 1 ? 1 : ((flags >> 8) & 1 ? -1 : 0); |
| 1177 | warn_c99_c11_compat = (flags >> 9) & 1 ? 1 : ((flags >> 10) & 1 ? -1 : 0); |
| 1178 | } |
| 1179 | |
| 1180 | /* Helper data structure for parsing #pragma acc routine. */ |
| 1181 | struct oacc_routine_data { |
| 1182 | bool error_seen; /* Set if error has been reported. */ |
| 1183 | bool fndecl_seen; /* Set if one fn decl/definition has been seen already. */ |
| 1184 | tree clauses; |
| 1185 | location_t loc; |
| 1186 | }; |
| 1187 | |
| 1188 | static void c_parser_external_declaration (c_parser *); |
| 1189 | static void c_parser_asm_definition (c_parser *); |
| 1190 | static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, |
| 1191 | bool, bool, tree *, vec<c_token>, |
| 1192 | struct oacc_routine_data * = NULL, |
| 1193 | bool * = NULL); |
| 1194 | static void c_parser_static_assert_declaration_no_semi (c_parser *); |
| 1195 | static void c_parser_static_assert_declaration (c_parser *); |
| 1196 | static struct c_typespec c_parser_enum_specifier (c_parser *); |
| 1197 | static struct c_typespec c_parser_struct_or_union_specifier (c_parser *); |
| 1198 | static tree c_parser_struct_declaration (c_parser *); |
| 1199 | static struct c_typespec c_parser_typeof_specifier (c_parser *); |
| 1200 | static tree c_parser_alignas_specifier (c_parser *); |
| 1201 | static struct c_declarator *c_parser_direct_declarator (c_parser *, bool, |
| 1202 | c_dtr_syn, bool *); |
| 1203 | static struct c_declarator *c_parser_direct_declarator_inner (c_parser *, |
| 1204 | bool, |
| 1205 | struct c_declarator *); |
| 1206 | static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree); |
| 1207 | static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree, |
| 1208 | tree); |
| 1209 | static struct c_parm *c_parser_parameter_declaration (c_parser *, tree); |
| 1210 | static tree c_parser_simple_asm_expr (c_parser *); |
| 1211 | static tree c_parser_attributes (c_parser *); |
| 1212 | static struct c_expr c_parser_initializer (c_parser *); |
| 1213 | static struct c_expr c_parser_braced_init (c_parser *, tree, bool, |
| 1214 | struct obstack *); |
| 1215 | static void c_parser_initelt (c_parser *, struct obstack *); |
| 1216 | static void c_parser_initval (c_parser *, struct c_expr *, |
| 1217 | struct obstack *); |
| 1218 | static tree c_parser_compound_statement (c_parser *); |
| 1219 | static void c_parser_compound_statement_nostart (c_parser *); |
| 1220 | static void c_parser_label (c_parser *); |
| 1221 | static void c_parser_statement (c_parser *, bool *); |
| 1222 | static void c_parser_statement_after_labels (c_parser *, bool *, |
| 1223 | vec<tree> * = NULL); |
| 1224 | static void c_parser_if_statement (c_parser *, bool *, vec<tree> *); |
| 1225 | static void c_parser_switch_statement (c_parser *, bool *); |
| 1226 | static void c_parser_while_statement (c_parser *, bool, bool *); |
| 1227 | static void c_parser_do_statement (c_parser *, bool); |
| 1228 | static void c_parser_for_statement (c_parser *, bool, bool *); |
| 1229 | static tree c_parser_asm_statement (c_parser *); |
| 1230 | static tree c_parser_asm_operands (c_parser *); |
| 1231 | static tree c_parser_asm_goto_operands (c_parser *); |
| 1232 | static tree c_parser_asm_clobbers (c_parser *); |
| 1233 | static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *, |
| 1234 | tree = NULL_TREE); |
| 1235 | static struct c_expr c_parser_conditional_expression (c_parser *, |
| 1236 | struct c_expr *, tree); |
| 1237 | static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *, |
| 1238 | tree); |
| 1239 | static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *); |
| 1240 | static struct c_expr c_parser_unary_expression (c_parser *); |
| 1241 | static struct c_expr c_parser_sizeof_expression (c_parser *); |
| 1242 | static struct c_expr c_parser_alignof_expression (c_parser *); |
| 1243 | static struct c_expr c_parser_postfix_expression (c_parser *); |
| 1244 | static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *, |
| 1245 | struct c_type_name *, |
| 1246 | location_t); |
| 1247 | static struct c_expr c_parser_postfix_expression_after_primary (c_parser *, |
| 1248 | location_t loc, |
| 1249 | struct c_expr); |
| 1250 | static tree c_parser_transaction (c_parser *, enum rid); |
| 1251 | static struct c_expr c_parser_transaction_expression (c_parser *, enum rid); |
| 1252 | static tree c_parser_transaction_cancel (c_parser *); |
| 1253 | static struct c_expr c_parser_expression (c_parser *); |
| 1254 | static struct c_expr c_parser_expression_conv (c_parser *); |
| 1255 | static vec<tree, va_gc> *c_parser_expr_list (c_parser *, bool, bool, |
| 1256 | vec<tree, va_gc> **, location_t *, |
| 1257 | tree *, vec<location_t> *, |
| 1258 | unsigned int * = NULL); |
| 1259 | static void c_parser_oacc_declare (c_parser *); |
| 1260 | static void c_parser_oacc_enter_exit_data (c_parser *, bool); |
| 1261 | static void c_parser_oacc_update (c_parser *); |
| 1262 | static void c_parser_omp_construct (c_parser *, bool *); |
| 1263 | static void c_parser_omp_threadprivate (c_parser *); |
| 1264 | static void c_parser_omp_barrier (c_parser *); |
| 1265 | static void c_parser_omp_flush (c_parser *); |
| 1266 | static tree c_parser_omp_for_loop (location_t, c_parser *, enum tree_code, |
| 1267 | tree, tree *, bool *); |
| 1268 | static void c_parser_omp_taskwait (c_parser *); |
| 1269 | static void c_parser_omp_taskyield (c_parser *); |
| 1270 | static void c_parser_omp_cancel (c_parser *); |
| 1271 | |
| 1272 | enum pragma_context { pragma_external, pragma_struct, pragma_param, |
| 1273 | pragma_stmt, pragma_compound }; |
| 1274 | static bool c_parser_pragma (c_parser *, enum pragma_context, bool *); |
| 1275 | static void c_parser_omp_cancellation_point (c_parser *, enum pragma_context); |
| 1276 | static bool c_parser_omp_target (c_parser *, enum pragma_context, bool *); |
| 1277 | static void c_parser_omp_end_declare_target (c_parser *); |
| 1278 | static void c_parser_omp_declare (c_parser *, enum pragma_context); |
| 1279 | static bool c_parser_omp_ordered (c_parser *, enum pragma_context, bool *); |
| 1280 | static void c_parser_oacc_routine (c_parser *, enum pragma_context); |
| 1281 | |
| 1282 | /* These Objective-C parser functions are only ever called when |
| 1283 | compiling Objective-C. */ |
| 1284 | static void c_parser_objc_class_definition (c_parser *, tree); |
| 1285 | static void c_parser_objc_class_instance_variables (c_parser *); |
| 1286 | static void c_parser_objc_class_declaration (c_parser *); |
| 1287 | static void c_parser_objc_alias_declaration (c_parser *); |
| 1288 | static void c_parser_objc_protocol_definition (c_parser *, tree); |
| 1289 | static bool c_parser_objc_method_type (c_parser *); |
| 1290 | static void c_parser_objc_method_definition (c_parser *); |
| 1291 | static void c_parser_objc_methodprotolist (c_parser *); |
| 1292 | static void c_parser_objc_methodproto (c_parser *); |
| 1293 | static tree c_parser_objc_method_decl (c_parser *, bool, tree *, tree *); |
| 1294 | static tree c_parser_objc_type_name (c_parser *); |
| 1295 | static tree c_parser_objc_protocol_refs (c_parser *); |
| 1296 | static void c_parser_objc_try_catch_finally_statement (c_parser *); |
| 1297 | static void c_parser_objc_synchronized_statement (c_parser *); |
| 1298 | static tree c_parser_objc_selector (c_parser *); |
| 1299 | static tree c_parser_objc_selector_arg (c_parser *); |
| 1300 | static tree c_parser_objc_receiver (c_parser *); |
| 1301 | static tree c_parser_objc_message_args (c_parser *); |
| 1302 | static tree c_parser_objc_keywordexpr (c_parser *); |
| 1303 | static void c_parser_objc_at_property_declaration (c_parser *); |
| 1304 | static void c_parser_objc_at_synthesize_declaration (c_parser *); |
| 1305 | static void c_parser_objc_at_dynamic_declaration (c_parser *); |
| 1306 | static bool c_parser_objc_diagnose_bad_element_prefix |
| 1307 | (c_parser *, struct c_declspecs *); |
| 1308 | |
| 1309 | /* Cilk Plus supporting routines. */ |
| 1310 | static void c_parser_cilk_simd (c_parser *, bool *); |
| 1311 | static void c_parser_cilk_for (c_parser *, tree, bool *); |
| 1312 | static bool c_parser_cilk_verify_simd (c_parser *, enum pragma_context); |
| 1313 | static tree c_parser_array_notation (location_t, c_parser *, tree, tree); |
| 1314 | static tree c_parser_cilk_clause_vectorlength (c_parser *, tree, bool); |
| 1315 | static void c_parser_cilk_grainsize (c_parser *, bool *); |
| 1316 | |
| 1317 | static void c_parser_parse_rtl_body (c_parser *parser, char *start_with_pass); |
| 1318 | |
| 1319 | /* Parse a translation unit (C90 6.7, C99 6.9, C11 6.9). |
| 1320 | |
| 1321 | translation-unit: |
| 1322 | external-declarations |
| 1323 | |
| 1324 | external-declarations: |
| 1325 | external-declaration |
| 1326 | external-declarations external-declaration |
| 1327 | |
| 1328 | GNU extensions: |
| 1329 | |
| 1330 | translation-unit: |
| 1331 | empty |
| 1332 | */ |
| 1333 | |
| 1334 | static void |
| 1335 | c_parser_translation_unit (c_parser *parser) |
| 1336 | { |
| 1337 | if (c_parser_next_token_is (parser, CPP_EOF)) |
| 1338 | { |
| 1339 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
| 1340 | "ISO C forbids an empty translation unit" ); |
| 1341 | } |
| 1342 | else |
| 1343 | { |
| 1344 | void *obstack_position = obstack_alloc (&parser_obstack, 0); |
| 1345 | mark_valid_location_for_stdc_pragma (false); |
| 1346 | do |
| 1347 | { |
| 1348 | ggc_collect (); |
| 1349 | c_parser_external_declaration (parser); |
| 1350 | obstack_free (&parser_obstack, obstack_position); |
| 1351 | } |
| 1352 | while (c_parser_next_token_is_not (parser, CPP_EOF)); |
| 1353 | } |
| 1354 | |
| 1355 | unsigned int i; |
| 1356 | tree decl; |
| 1357 | FOR_EACH_VEC_ELT (incomplete_record_decls, i, decl) |
| 1358 | if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node) |
| 1359 | error ("storage size of %q+D isn%'t known" , decl); |
| 1360 | } |
| 1361 | |
| 1362 | /* Parse an external declaration (C90 6.7, C99 6.9, C11 6.9). |
| 1363 | |
| 1364 | external-declaration: |
| 1365 | function-definition |
| 1366 | declaration |
| 1367 | |
| 1368 | GNU extensions: |
| 1369 | |
| 1370 | external-declaration: |
| 1371 | asm-definition |
| 1372 | ; |
| 1373 | __extension__ external-declaration |
| 1374 | |
| 1375 | Objective-C: |
| 1376 | |
| 1377 | external-declaration: |
| 1378 | objc-class-definition |
| 1379 | objc-class-declaration |
| 1380 | objc-alias-declaration |
| 1381 | objc-protocol-definition |
| 1382 | objc-method-definition |
| 1383 | @end |
| 1384 | */ |
| 1385 | |
| 1386 | static void |
| 1387 | c_parser_external_declaration (c_parser *parser) |
| 1388 | { |
| 1389 | int ext; |
| 1390 | switch (c_parser_peek_token (parser)->type) |
| 1391 | { |
| 1392 | case CPP_KEYWORD: |
| 1393 | switch (c_parser_peek_token (parser)->keyword) |
| 1394 | { |
| 1395 | case RID_EXTENSION: |
| 1396 | ext = disable_extension_diagnostics (); |
| 1397 | c_parser_consume_token (parser); |
| 1398 | c_parser_external_declaration (parser); |
| 1399 | restore_extension_diagnostics (ext); |
| 1400 | break; |
| 1401 | case RID_ASM: |
| 1402 | c_parser_asm_definition (parser); |
| 1403 | break; |
| 1404 | case RID_AT_INTERFACE: |
| 1405 | case RID_AT_IMPLEMENTATION: |
| 1406 | gcc_assert (c_dialect_objc ()); |
| 1407 | c_parser_objc_class_definition (parser, NULL_TREE); |
| 1408 | break; |
| 1409 | case RID_AT_CLASS: |
| 1410 | gcc_assert (c_dialect_objc ()); |
| 1411 | c_parser_objc_class_declaration (parser); |
| 1412 | break; |
| 1413 | case RID_AT_ALIAS: |
| 1414 | gcc_assert (c_dialect_objc ()); |
| 1415 | c_parser_objc_alias_declaration (parser); |
| 1416 | break; |
| 1417 | case RID_AT_PROTOCOL: |
| 1418 | gcc_assert (c_dialect_objc ()); |
| 1419 | c_parser_objc_protocol_definition (parser, NULL_TREE); |
| 1420 | break; |
| 1421 | case RID_AT_PROPERTY: |
| 1422 | gcc_assert (c_dialect_objc ()); |
| 1423 | c_parser_objc_at_property_declaration (parser); |
| 1424 | break; |
| 1425 | case RID_AT_SYNTHESIZE: |
| 1426 | gcc_assert (c_dialect_objc ()); |
| 1427 | c_parser_objc_at_synthesize_declaration (parser); |
| 1428 | break; |
| 1429 | case RID_AT_DYNAMIC: |
| 1430 | gcc_assert (c_dialect_objc ()); |
| 1431 | c_parser_objc_at_dynamic_declaration (parser); |
| 1432 | break; |
| 1433 | case RID_AT_END: |
| 1434 | gcc_assert (c_dialect_objc ()); |
| 1435 | c_parser_consume_token (parser); |
| 1436 | objc_finish_implementation (); |
| 1437 | break; |
| 1438 | default: |
| 1439 | goto decl_or_fndef; |
| 1440 | } |
| 1441 | break; |
| 1442 | case CPP_SEMICOLON: |
| 1443 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
| 1444 | "ISO C does not allow extra %<;%> outside of a function" ); |
| 1445 | c_parser_consume_token (parser); |
| 1446 | break; |
| 1447 | case CPP_PRAGMA: |
| 1448 | mark_valid_location_for_stdc_pragma (true); |
| 1449 | c_parser_pragma (parser, pragma_external, NULL); |
| 1450 | mark_valid_location_for_stdc_pragma (false); |
| 1451 | break; |
| 1452 | case CPP_PLUS: |
| 1453 | case CPP_MINUS: |
| 1454 | if (c_dialect_objc ()) |
| 1455 | { |
| 1456 | c_parser_objc_method_definition (parser); |
| 1457 | break; |
| 1458 | } |
| 1459 | /* Else fall through, and yield a syntax error trying to parse |
| 1460 | as a declaration or function definition. */ |
| 1461 | /* FALLTHRU */ |
| 1462 | default: |
| 1463 | decl_or_fndef: |
| 1464 | /* A declaration or a function definition (or, in Objective-C, |
| 1465 | an @interface or @protocol with prefix attributes). We can |
| 1466 | only tell which after parsing the declaration specifiers, if |
| 1467 | any, and the first declarator. */ |
| 1468 | c_parser_declaration_or_fndef (parser, true, true, true, false, true, |
| 1469 | NULL, vNULL); |
| 1470 | break; |
| 1471 | } |
| 1472 | } |
| 1473 | |
| 1474 | static void c_finish_omp_declare_simd (c_parser *, tree, tree, vec<c_token>); |
| 1475 | static void c_finish_oacc_routine (struct oacc_routine_data *, tree, bool); |
| 1476 | |
| 1477 | /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99 |
| 1478 | 6.7, 6.9.1, C11 6.7, 6.9.1). If FNDEF_OK is true, a function definition |
| 1479 | is accepted; otherwise (old-style parameter declarations) only other |
| 1480 | declarations are accepted. If STATIC_ASSERT_OK is true, a static |
| 1481 | assertion is accepted; otherwise (old-style parameter declarations) |
| 1482 | it is not. If NESTED is true, we are inside a function or parsing |
| 1483 | old-style parameter declarations; any functions encountered are |
| 1484 | nested functions and declaration specifiers are required; otherwise |
| 1485 | we are at top level and functions are normal functions and |
| 1486 | declaration specifiers may be optional. If EMPTY_OK is true, empty |
| 1487 | declarations are OK (subject to all other constraints); otherwise |
| 1488 | (old-style parameter declarations) they are diagnosed. If |
| 1489 | START_ATTR_OK is true, the declaration specifiers may start with |
| 1490 | attributes; otherwise they may not. |
| 1491 | OBJC_FOREACH_OBJECT_DECLARATION can be used to get back the parsed |
| 1492 | declaration when parsing an Objective-C foreach statement. |
| 1493 | FALLTHRU_ATTR_P is used to signal whether this function parsed |
| 1494 | "__attribute__((fallthrough));". |
| 1495 | |
| 1496 | declaration: |
| 1497 | declaration-specifiers init-declarator-list[opt] ; |
| 1498 | static_assert-declaration |
| 1499 | |
| 1500 | function-definition: |
| 1501 | declaration-specifiers[opt] declarator declaration-list[opt] |
| 1502 | compound-statement |
| 1503 | |
| 1504 | declaration-list: |
| 1505 | declaration |
| 1506 | declaration-list declaration |
| 1507 | |
| 1508 | init-declarator-list: |
| 1509 | init-declarator |
| 1510 | init-declarator-list , init-declarator |
| 1511 | |
| 1512 | init-declarator: |
| 1513 | declarator simple-asm-expr[opt] attributes[opt] |
| 1514 | declarator simple-asm-expr[opt] attributes[opt] = initializer |
| 1515 | |
| 1516 | GNU extensions: |
| 1517 | |
| 1518 | nested-function-definition: |
| 1519 | declaration-specifiers declarator declaration-list[opt] |
| 1520 | compound-statement |
| 1521 | |
| 1522 | attribute ; |
| 1523 | |
| 1524 | Objective-C: |
| 1525 | attributes objc-class-definition |
| 1526 | attributes objc-category-definition |
| 1527 | attributes objc-protocol-definition |
| 1528 | |
| 1529 | The simple-asm-expr and attributes are GNU extensions. |
| 1530 | |
| 1531 | This function does not handle __extension__; that is handled in its |
| 1532 | callers. ??? Following the old parser, __extension__ may start |
| 1533 | external declarations, declarations in functions and declarations |
| 1534 | at the start of "for" loops, but not old-style parameter |
| 1535 | declarations. |
| 1536 | |
| 1537 | C99 requires declaration specifiers in a function definition; the |
| 1538 | absence is diagnosed through the diagnosis of implicit int. In GNU |
| 1539 | C we also allow but diagnose declarations without declaration |
| 1540 | specifiers, but only at top level (elsewhere they conflict with |
| 1541 | other syntax). |
| 1542 | |
| 1543 | In Objective-C, declarations of the looping variable in a foreach |
| 1544 | statement are exceptionally terminated by 'in' (for example, 'for |
| 1545 | (NSObject *object in array) { ... }'). |
| 1546 | |
| 1547 | OpenMP: |
| 1548 | |
| 1549 | declaration: |
| 1550 | threadprivate-directive |
| 1551 | |
| 1552 | GIMPLE: |
| 1553 | |
| 1554 | gimple-function-definition: |
| 1555 | declaration-specifiers[opt] __GIMPLE (gimple-or-rtl-pass-list) declarator |
| 1556 | declaration-list[opt] compound-statement |
| 1557 | |
| 1558 | rtl-function-definition: |
| 1559 | declaration-specifiers[opt] __RTL (gimple-or-rtl-pass-list) declarator |
| 1560 | declaration-list[opt] compound-statement */ |
| 1561 | |
| 1562 | static void |
| 1563 | c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, |
| 1564 | bool static_assert_ok, bool empty_ok, |
| 1565 | bool nested, bool start_attr_ok, |
| 1566 | tree *objc_foreach_object_declaration, |
| 1567 | vec<c_token> omp_declare_simd_clauses, |
| 1568 | struct oacc_routine_data *oacc_routine_data, |
| 1569 | bool *fallthru_attr_p) |
| 1570 | { |
| 1571 | struct c_declspecs *specs; |
| 1572 | tree prefix_attrs; |
| 1573 | tree all_prefix_attrs; |
| 1574 | bool diagnosed_no_specs = false; |
| 1575 | location_t here = c_parser_peek_token (parser)->location; |
| 1576 | |
| 1577 | if (static_assert_ok |
| 1578 | && c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)) |
| 1579 | { |
| 1580 | c_parser_static_assert_declaration (parser); |
| 1581 | return; |
| 1582 | } |
| 1583 | specs = build_null_declspecs (); |
| 1584 | |
| 1585 | /* Try to detect an unknown type name when we have "A B" or "A *B". */ |
| 1586 | if (c_parser_peek_token (parser)->type == CPP_NAME |
| 1587 | && c_parser_peek_token (parser)->id_kind == C_ID_ID |
| 1588 | && (c_parser_peek_2nd_token (parser)->type == CPP_NAME |
| 1589 | || c_parser_peek_2nd_token (parser)->type == CPP_MULT) |
| 1590 | && (!nested || !lookup_name (c_parser_peek_token (parser)->value))) |
| 1591 | { |
| 1592 | tree name = c_parser_peek_token (parser)->value; |
| 1593 | |
| 1594 | /* Issue a warning about NAME being an unknown type name, perhaps |
| 1595 | with some kind of hint. |
| 1596 | If the user forgot a "struct" etc, suggest inserting |
| 1597 | it. Otherwise, attempt to look for misspellings. */ |
| 1598 | gcc_rich_location richloc (here); |
| 1599 | if (tag_exists_p (RECORD_TYPE, name)) |
| 1600 | { |
| 1601 | /* This is not C++ with its implicit typedef. */ |
| 1602 | richloc.add_fixit_insert_before ("struct " ); |
| 1603 | error_at_rich_loc (&richloc, |
| 1604 | "unknown type name %qE;" |
| 1605 | " use %<struct%> keyword to refer to the type" , |
| 1606 | name); |
| 1607 | } |
| 1608 | else if (tag_exists_p (UNION_TYPE, name)) |
| 1609 | { |
| 1610 | richloc.add_fixit_insert_before ("union " ); |
| 1611 | error_at_rich_loc (&richloc, |
| 1612 | "unknown type name %qE;" |
| 1613 | " use %<union%> keyword to refer to the type" , |
| 1614 | name); |
| 1615 | } |
| 1616 | else if (tag_exists_p (ENUMERAL_TYPE, name)) |
| 1617 | { |
| 1618 | richloc.add_fixit_insert_before ("enum " ); |
| 1619 | error_at_rich_loc (&richloc, |
| 1620 | "unknown type name %qE;" |
| 1621 | " use %<enum%> keyword to refer to the type" , |
| 1622 | name); |
| 1623 | } |
| 1624 | else |
| 1625 | { |
| 1626 | const char *hint = lookup_name_fuzzy (name, FUZZY_LOOKUP_TYPENAME); |
| 1627 | if (hint) |
| 1628 | { |
| 1629 | richloc.add_fixit_replace (hint); |
| 1630 | error_at_rich_loc (&richloc, |
| 1631 | "unknown type name %qE; did you mean %qs?" , |
| 1632 | name, hint); |
| 1633 | } |
| 1634 | else |
| 1635 | error_at (here, "unknown type name %qE" , name); |
| 1636 | } |
| 1637 | |
| 1638 | /* Parse declspecs normally to get a correct pointer type, but avoid |
| 1639 | a further "fails to be a type name" error. Refuse nested functions |
| 1640 | since it is not how the user likely wants us to recover. */ |
| 1641 | c_parser_peek_token (parser)->type = CPP_KEYWORD; |
| 1642 | c_parser_peek_token (parser)->keyword = RID_VOID; |
| 1643 | c_parser_peek_token (parser)->value = error_mark_node; |
| 1644 | fndef_ok = !nested; |
| 1645 | } |
| 1646 | |
| 1647 | c_parser_declspecs (parser, specs, true, true, start_attr_ok, |
| 1648 | true, true, cla_nonabstract_decl); |
| 1649 | if (parser->error) |
| 1650 | { |
| 1651 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 1652 | return; |
| 1653 | } |
| 1654 | if (nested && !specs->declspecs_seen_p) |
| 1655 | { |
| 1656 | c_parser_error (parser, "expected declaration specifiers" ); |
| 1657 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 1658 | return; |
| 1659 | } |
| 1660 | |
| 1661 | finish_declspecs (specs); |
| 1662 | bool auto_type_p = specs->typespec_word == cts_auto_type; |
| 1663 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 1664 | { |
| 1665 | if (auto_type_p) |
| 1666 | error_at (here, "%<__auto_type%> in empty declaration" ); |
| 1667 | else if (specs->typespec_kind == ctsk_none |
| 1668 | && attribute_fallthrough_p (specs->attrs)) |
| 1669 | { |
| 1670 | if (fallthru_attr_p != NULL) |
| 1671 | *fallthru_attr_p = true; |
| 1672 | tree fn = build_call_expr_internal_loc (here, IFN_FALLTHROUGH, |
| 1673 | void_type_node, 0); |
| 1674 | add_stmt (fn); |
| 1675 | } |
| 1676 | else if (empty_ok) |
| 1677 | shadow_tag (specs); |
| 1678 | else |
| 1679 | { |
| 1680 | shadow_tag_warned (specs, 1); |
| 1681 | pedwarn (here, 0, "empty declaration" ); |
| 1682 | } |
| 1683 | c_parser_consume_token (parser); |
| 1684 | if (oacc_routine_data) |
| 1685 | c_finish_oacc_routine (oacc_routine_data, NULL_TREE, false); |
| 1686 | return; |
| 1687 | } |
| 1688 | |
| 1689 | /* Provide better error recovery. Note that a type name here is usually |
| 1690 | better diagnosed as a redeclaration. */ |
| 1691 | if (empty_ok |
| 1692 | && specs->typespec_kind == ctsk_tagdef |
| 1693 | && c_parser_next_token_starts_declspecs (parser) |
| 1694 | && !c_parser_next_token_is (parser, CPP_NAME)) |
| 1695 | { |
| 1696 | c_parser_error (parser, "expected %<;%>, identifier or %<(%>" ); |
| 1697 | parser->error = false; |
| 1698 | shadow_tag_warned (specs, 1); |
| 1699 | return; |
| 1700 | } |
| 1701 | else if (c_dialect_objc () && !auto_type_p) |
| 1702 | { |
| 1703 | /* Prefix attributes are an error on method decls. */ |
| 1704 | switch (c_parser_peek_token (parser)->type) |
| 1705 | { |
| 1706 | case CPP_PLUS: |
| 1707 | case CPP_MINUS: |
| 1708 | if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) |
| 1709 | return; |
| 1710 | if (specs->attrs) |
| 1711 | { |
| 1712 | warning_at (c_parser_peek_token (parser)->location, |
| 1713 | OPT_Wattributes, |
| 1714 | "prefix attributes are ignored for methods" ); |
| 1715 | specs->attrs = NULL_TREE; |
| 1716 | } |
| 1717 | if (fndef_ok) |
| 1718 | c_parser_objc_method_definition (parser); |
| 1719 | else |
| 1720 | c_parser_objc_methodproto (parser); |
| 1721 | return; |
| 1722 | break; |
| 1723 | default: |
| 1724 | break; |
| 1725 | } |
| 1726 | /* This is where we parse 'attributes @interface ...', |
| 1727 | 'attributes @implementation ...', 'attributes @protocol ...' |
| 1728 | (where attributes could be, for example, __attribute__ |
| 1729 | ((deprecated)). |
| 1730 | */ |
| 1731 | switch (c_parser_peek_token (parser)->keyword) |
| 1732 | { |
| 1733 | case RID_AT_INTERFACE: |
| 1734 | { |
| 1735 | if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) |
| 1736 | return; |
| 1737 | c_parser_objc_class_definition (parser, specs->attrs); |
| 1738 | return; |
| 1739 | } |
| 1740 | break; |
| 1741 | case RID_AT_IMPLEMENTATION: |
| 1742 | { |
| 1743 | if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) |
| 1744 | return; |
| 1745 | if (specs->attrs) |
| 1746 | { |
| 1747 | warning_at (c_parser_peek_token (parser)->location, |
| 1748 | OPT_Wattributes, |
| 1749 | "prefix attributes are ignored for implementations" ); |
| 1750 | specs->attrs = NULL_TREE; |
| 1751 | } |
| 1752 | c_parser_objc_class_definition (parser, NULL_TREE); |
| 1753 | return; |
| 1754 | } |
| 1755 | break; |
| 1756 | case RID_AT_PROTOCOL: |
| 1757 | { |
| 1758 | if (c_parser_objc_diagnose_bad_element_prefix (parser, specs)) |
| 1759 | return; |
| 1760 | c_parser_objc_protocol_definition (parser, specs->attrs); |
| 1761 | return; |
| 1762 | } |
| 1763 | break; |
| 1764 | case RID_AT_ALIAS: |
| 1765 | case RID_AT_CLASS: |
| 1766 | case RID_AT_END: |
| 1767 | case RID_AT_PROPERTY: |
| 1768 | if (specs->attrs) |
| 1769 | { |
| 1770 | c_parser_error (parser, "unexpected attribute" ); |
| 1771 | specs->attrs = NULL; |
| 1772 | } |
| 1773 | break; |
| 1774 | default: |
| 1775 | break; |
| 1776 | } |
| 1777 | } |
| 1778 | else if (attribute_fallthrough_p (specs->attrs)) |
| 1779 | warning_at (here, OPT_Wattributes, |
| 1780 | "%<fallthrough%> attribute not followed by %<;%>" ); |
| 1781 | |
| 1782 | pending_xref_error (); |
| 1783 | prefix_attrs = specs->attrs; |
| 1784 | all_prefix_attrs = prefix_attrs; |
| 1785 | specs->attrs = NULL_TREE; |
| 1786 | while (true) |
| 1787 | { |
| 1788 | struct c_declarator *declarator; |
| 1789 | bool dummy = false; |
| 1790 | timevar_id_t tv; |
| 1791 | tree fnbody = NULL_TREE; |
| 1792 | /* Declaring either one or more declarators (in which case we |
| 1793 | should diagnose if there were no declaration specifiers) or a |
| 1794 | function definition (in which case the diagnostic for |
| 1795 | implicit int suffices). */ |
| 1796 | declarator = c_parser_declarator (parser, |
| 1797 | specs->typespec_kind != ctsk_none, |
| 1798 | C_DTR_NORMAL, &dummy); |
| 1799 | if (declarator == NULL) |
| 1800 | { |
| 1801 | if (omp_declare_simd_clauses.exists () |
| 1802 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) |
| 1803 | c_finish_omp_declare_simd (parser, NULL_TREE, NULL_TREE, |
| 1804 | omp_declare_simd_clauses); |
| 1805 | if (oacc_routine_data) |
| 1806 | c_finish_oacc_routine (oacc_routine_data, NULL_TREE, false); |
| 1807 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 1808 | return; |
| 1809 | } |
| 1810 | if (auto_type_p && declarator->kind != cdk_id) |
| 1811 | { |
| 1812 | error_at (here, |
| 1813 | "%<__auto_type%> requires a plain identifier" |
| 1814 | " as declarator" ); |
| 1815 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 1816 | return; |
| 1817 | } |
| 1818 | if (c_parser_next_token_is (parser, CPP_EQ) |
| 1819 | || c_parser_next_token_is (parser, CPP_COMMA) |
| 1820 | || c_parser_next_token_is (parser, CPP_SEMICOLON) |
| 1821 | || c_parser_next_token_is_keyword (parser, RID_ASM) |
| 1822 | || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE) |
| 1823 | || c_parser_next_token_is_keyword (parser, RID_IN)) |
| 1824 | { |
| 1825 | tree asm_name = NULL_TREE; |
| 1826 | tree postfix_attrs = NULL_TREE; |
| 1827 | if (!diagnosed_no_specs && !specs->declspecs_seen_p) |
| 1828 | { |
| 1829 | diagnosed_no_specs = true; |
| 1830 | pedwarn (here, 0, "data definition has no type or storage class" ); |
| 1831 | } |
| 1832 | /* Having seen a data definition, there cannot now be a |
| 1833 | function definition. */ |
| 1834 | fndef_ok = false; |
| 1835 | if (c_parser_next_token_is_keyword (parser, RID_ASM)) |
| 1836 | asm_name = c_parser_simple_asm_expr (parser); |
| 1837 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 1838 | { |
| 1839 | postfix_attrs = c_parser_attributes (parser); |
| 1840 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 1841 | { |
| 1842 | /* This means there is an attribute specifier after |
| 1843 | the declarator in a function definition. Provide |
| 1844 | some more information for the user. */ |
| 1845 | error_at (here, "attributes should be specified before the " |
| 1846 | "declarator in a function definition" ); |
| 1847 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 1848 | return; |
| 1849 | } |
| 1850 | } |
| 1851 | if (c_parser_next_token_is (parser, CPP_EQ)) |
| 1852 | { |
| 1853 | tree d; |
| 1854 | struct c_expr init; |
| 1855 | location_t init_loc; |
| 1856 | c_parser_consume_token (parser); |
| 1857 | if (auto_type_p) |
| 1858 | { |
| 1859 | init_loc = c_parser_peek_token (parser)->location; |
| 1860 | rich_location richloc (line_table, init_loc); |
| 1861 | start_init (NULL_TREE, asm_name, global_bindings_p (), &richloc); |
| 1862 | /* A parameter is initialized, which is invalid. Don't |
| 1863 | attempt to instrument the initializer. */ |
| 1864 | int flag_sanitize_save = flag_sanitize; |
| 1865 | if (nested && !empty_ok) |
| 1866 | flag_sanitize = 0; |
| 1867 | init = c_parser_expr_no_commas (parser, NULL); |
| 1868 | flag_sanitize = flag_sanitize_save; |
| 1869 | if (TREE_CODE (init.value) == COMPONENT_REF |
| 1870 | && DECL_C_BIT_FIELD (TREE_OPERAND (init.value, 1))) |
| 1871 | error_at (here, |
| 1872 | "%<__auto_type%> used with a bit-field" |
| 1873 | " initializer" ); |
| 1874 | init = convert_lvalue_to_rvalue (init_loc, init, true, true); |
| 1875 | tree init_type = TREE_TYPE (init.value); |
| 1876 | /* As with typeof, remove all qualifiers from atomic types. */ |
| 1877 | if (init_type != error_mark_node && TYPE_ATOMIC (init_type)) |
| 1878 | init_type |
| 1879 | = c_build_qualified_type (init_type, TYPE_UNQUALIFIED); |
| 1880 | bool vm_type = variably_modified_type_p (init_type, |
| 1881 | NULL_TREE); |
| 1882 | if (vm_type) |
| 1883 | init.value = c_save_expr (init.value); |
| 1884 | finish_init (); |
| 1885 | specs->typespec_kind = ctsk_typeof; |
| 1886 | specs->locations[cdw_typedef] = init_loc; |
| 1887 | specs->typedef_p = true; |
| 1888 | specs->type = init_type; |
| 1889 | if (vm_type) |
| 1890 | { |
| 1891 | bool maybe_const = true; |
| 1892 | tree type_expr = c_fully_fold (init.value, false, |
| 1893 | &maybe_const); |
| 1894 | specs->expr_const_operands &= maybe_const; |
| 1895 | if (specs->expr) |
| 1896 | specs->expr = build2 (COMPOUND_EXPR, |
| 1897 | TREE_TYPE (type_expr), |
| 1898 | specs->expr, type_expr); |
| 1899 | else |
| 1900 | specs->expr = type_expr; |
| 1901 | } |
| 1902 | d = start_decl (declarator, specs, true, |
| 1903 | chainon (postfix_attrs, all_prefix_attrs)); |
| 1904 | if (!d) |
| 1905 | d = error_mark_node; |
| 1906 | if (omp_declare_simd_clauses.exists () |
| 1907 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) |
| 1908 | c_finish_omp_declare_simd (parser, d, NULL_TREE, |
| 1909 | omp_declare_simd_clauses); |
| 1910 | } |
| 1911 | else |
| 1912 | { |
| 1913 | /* The declaration of the variable is in effect while |
| 1914 | its initializer is parsed. */ |
| 1915 | d = start_decl (declarator, specs, true, |
| 1916 | chainon (postfix_attrs, all_prefix_attrs)); |
| 1917 | if (!d) |
| 1918 | d = error_mark_node; |
| 1919 | if (omp_declare_simd_clauses.exists () |
| 1920 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) |
| 1921 | c_finish_omp_declare_simd (parser, d, NULL_TREE, |
| 1922 | omp_declare_simd_clauses); |
| 1923 | init_loc = c_parser_peek_token (parser)->location; |
| 1924 | rich_location richloc (line_table, init_loc); |
| 1925 | start_init (d, asm_name, global_bindings_p (), &richloc); |
| 1926 | /* A parameter is initialized, which is invalid. Don't |
| 1927 | attempt to instrument the initializer. */ |
| 1928 | int flag_sanitize_save = flag_sanitize; |
| 1929 | if (TREE_CODE (d) == PARM_DECL) |
| 1930 | flag_sanitize = 0; |
| 1931 | init = c_parser_initializer (parser); |
| 1932 | flag_sanitize = flag_sanitize_save; |
| 1933 | finish_init (); |
| 1934 | } |
| 1935 | if (oacc_routine_data) |
| 1936 | c_finish_oacc_routine (oacc_routine_data, d, false); |
| 1937 | if (d != error_mark_node) |
| 1938 | { |
| 1939 | maybe_warn_string_init (init_loc, TREE_TYPE (d), init); |
| 1940 | finish_decl (d, init_loc, init.value, |
| 1941 | init.original_type, asm_name); |
| 1942 | } |
| 1943 | } |
| 1944 | else |
| 1945 | { |
| 1946 | if (auto_type_p) |
| 1947 | { |
| 1948 | error_at (here, |
| 1949 | "%<__auto_type%> requires an initialized " |
| 1950 | "data declaration" ); |
| 1951 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 1952 | return; |
| 1953 | } |
| 1954 | tree d = start_decl (declarator, specs, false, |
| 1955 | chainon (postfix_attrs, |
| 1956 | all_prefix_attrs)); |
| 1957 | if (omp_declare_simd_clauses.exists () |
| 1958 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) |
| 1959 | { |
| 1960 | tree parms = NULL_TREE; |
| 1961 | if (d && TREE_CODE (d) == FUNCTION_DECL) |
| 1962 | { |
| 1963 | struct c_declarator *ce = declarator; |
| 1964 | while (ce != NULL) |
| 1965 | if (ce->kind == cdk_function) |
| 1966 | { |
| 1967 | parms = ce->u.arg_info->parms; |
| 1968 | break; |
| 1969 | } |
| 1970 | else |
| 1971 | ce = ce->declarator; |
| 1972 | } |
| 1973 | if (parms) |
| 1974 | temp_store_parm_decls (d, parms); |
| 1975 | c_finish_omp_declare_simd (parser, d, parms, |
| 1976 | omp_declare_simd_clauses); |
| 1977 | if (parms) |
| 1978 | temp_pop_parm_decls (); |
| 1979 | } |
| 1980 | if (oacc_routine_data) |
| 1981 | c_finish_oacc_routine (oacc_routine_data, d, false); |
| 1982 | if (d) |
| 1983 | finish_decl (d, UNKNOWN_LOCATION, NULL_TREE, |
| 1984 | NULL_TREE, asm_name); |
| 1985 | |
| 1986 | if (c_parser_next_token_is_keyword (parser, RID_IN)) |
| 1987 | { |
| 1988 | if (d) |
| 1989 | *objc_foreach_object_declaration = d; |
| 1990 | else |
| 1991 | *objc_foreach_object_declaration = error_mark_node; |
| 1992 | } |
| 1993 | } |
| 1994 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 1995 | { |
| 1996 | if (auto_type_p) |
| 1997 | { |
| 1998 | error_at (here, |
| 1999 | "%<__auto_type%> may only be used with" |
| 2000 | " a single declarator" ); |
| 2001 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 2002 | return; |
| 2003 | } |
| 2004 | c_parser_consume_token (parser); |
| 2005 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 2006 | all_prefix_attrs = chainon (c_parser_attributes (parser), |
| 2007 | prefix_attrs); |
| 2008 | else |
| 2009 | all_prefix_attrs = prefix_attrs; |
| 2010 | continue; |
| 2011 | } |
| 2012 | else if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 2013 | { |
| 2014 | c_parser_consume_token (parser); |
| 2015 | return; |
| 2016 | } |
| 2017 | else if (c_parser_next_token_is_keyword (parser, RID_IN)) |
| 2018 | { |
| 2019 | /* This can only happen in Objective-C: we found the |
| 2020 | 'in' that terminates the declaration inside an |
| 2021 | Objective-C foreach statement. Do not consume the |
| 2022 | token, so that the caller can use it to determine |
| 2023 | that this indeed is a foreach context. */ |
| 2024 | return; |
| 2025 | } |
| 2026 | else |
| 2027 | { |
| 2028 | c_parser_error (parser, "expected %<,%> or %<;%>" ); |
| 2029 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 2030 | return; |
| 2031 | } |
| 2032 | } |
| 2033 | else if (auto_type_p) |
| 2034 | { |
| 2035 | error_at (here, |
| 2036 | "%<__auto_type%> requires an initialized data declaration" ); |
| 2037 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 2038 | return; |
| 2039 | } |
| 2040 | else if (!fndef_ok) |
| 2041 | { |
| 2042 | c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, " |
| 2043 | "%<asm%> or %<__attribute__%>" ); |
| 2044 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 2045 | return; |
| 2046 | } |
| 2047 | /* Function definition (nested or otherwise). */ |
| 2048 | if (nested) |
| 2049 | { |
| 2050 | pedwarn (here, OPT_Wpedantic, "ISO C forbids nested functions" ); |
| 2051 | c_push_function_context (); |
| 2052 | } |
| 2053 | if (!start_function (specs, declarator, all_prefix_attrs)) |
| 2054 | { |
| 2055 | /* This can appear in many cases looking nothing like a |
| 2056 | function definition, so we don't give a more specific |
| 2057 | error suggesting there was one. */ |
| 2058 | c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> " |
| 2059 | "or %<__attribute__%>" ); |
| 2060 | if (nested) |
| 2061 | c_pop_function_context (); |
| 2062 | break; |
| 2063 | } |
| 2064 | |
| 2065 | if (DECL_DECLARED_INLINE_P (current_function_decl)) |
| 2066 | tv = TV_PARSE_INLINE; |
| 2067 | else |
| 2068 | tv = TV_PARSE_FUNC; |
| 2069 | auto_timevar at (g_timer, tv); |
| 2070 | |
| 2071 | /* Parse old-style parameter declarations. ??? Attributes are |
| 2072 | not allowed to start declaration specifiers here because of a |
| 2073 | syntax conflict between a function declaration with attribute |
| 2074 | suffix and a function definition with an attribute prefix on |
| 2075 | first old-style parameter declaration. Following the old |
| 2076 | parser, they are not accepted on subsequent old-style |
| 2077 | parameter declarations either. However, there is no |
| 2078 | ambiguity after the first declaration, nor indeed on the |
| 2079 | first as long as we don't allow postfix attributes after a |
| 2080 | declarator with a nonempty identifier list in a definition; |
| 2081 | and postfix attributes have never been accepted here in |
| 2082 | function definitions either. */ |
| 2083 | while (c_parser_next_token_is_not (parser, CPP_EOF) |
| 2084 | && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE)) |
| 2085 | c_parser_declaration_or_fndef (parser, false, false, false, |
| 2086 | true, false, NULL, vNULL); |
| 2087 | store_parm_decls (); |
| 2088 | if (omp_declare_simd_clauses.exists () |
| 2089 | || !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) |
| 2090 | c_finish_omp_declare_simd (parser, current_function_decl, NULL_TREE, |
| 2091 | omp_declare_simd_clauses); |
| 2092 | if (oacc_routine_data) |
| 2093 | c_finish_oacc_routine (oacc_routine_data, current_function_decl, true); |
| 2094 | DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus |
| 2095 | = c_parser_peek_token (parser)->location; |
| 2096 | |
| 2097 | /* If the definition was marked with __GIMPLE then parse the |
| 2098 | function body as GIMPLE. */ |
| 2099 | if (specs->gimple_p) |
| 2100 | { |
| 2101 | cfun->pass_startwith = specs->gimple_or_rtl_pass; |
| 2102 | bool saved = in_late_binary_op; |
| 2103 | in_late_binary_op = true; |
| 2104 | c_parser_parse_gimple_body (parser); |
| 2105 | in_late_binary_op = saved; |
| 2106 | } |
| 2107 | /* Similarly, if it was marked with __RTL, use the RTL parser now, |
| 2108 | consuming the function body. */ |
| 2109 | else if (specs->rtl_p) |
| 2110 | { |
| 2111 | c_parser_parse_rtl_body (parser, specs->gimple_or_rtl_pass); |
| 2112 | |
| 2113 | /* Normally, store_parm_decls sets next_is_function_body, |
| 2114 | anticipating a function body. We need a push_scope/pop_scope |
| 2115 | pair to flush out this state, or subsequent function parsing |
| 2116 | will go wrong. */ |
| 2117 | push_scope (); |
| 2118 | pop_scope (); |
| 2119 | |
| 2120 | finish_function (); |
| 2121 | return; |
| 2122 | } |
| 2123 | else |
| 2124 | { |
| 2125 | fnbody = c_parser_compound_statement (parser); |
| 2126 | if (flag_cilkplus && contains_array_notation_expr (fnbody)) |
| 2127 | fnbody = expand_array_notation_exprs (fnbody); |
| 2128 | } |
| 2129 | tree fndecl = current_function_decl; |
| 2130 | if (nested) |
| 2131 | { |
| 2132 | tree decl = current_function_decl; |
| 2133 | /* Mark nested functions as needing static-chain initially. |
| 2134 | lower_nested_functions will recompute it but the |
| 2135 | DECL_STATIC_CHAIN flag is also used before that happens, |
| 2136 | by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */ |
| 2137 | DECL_STATIC_CHAIN (decl) = 1; |
| 2138 | add_stmt (fnbody); |
| 2139 | finish_function (); |
| 2140 | c_pop_function_context (); |
| 2141 | add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl)); |
| 2142 | } |
| 2143 | else |
| 2144 | { |
| 2145 | if (fnbody) |
| 2146 | add_stmt (fnbody); |
| 2147 | finish_function (); |
| 2148 | } |
| 2149 | /* Get rid of the empty stmt list for GIMPLE. */ |
| 2150 | if (specs->gimple_p) |
| 2151 | DECL_SAVED_TREE (fndecl) = NULL_TREE; |
| 2152 | |
| 2153 | break; |
| 2154 | } |
| 2155 | } |
| 2156 | |
| 2157 | /* Parse an asm-definition (asm() outside a function body). This is a |
| 2158 | GNU extension. |
| 2159 | |
| 2160 | asm-definition: |
| 2161 | simple-asm-expr ; |
| 2162 | */ |
| 2163 | |
| 2164 | static void |
| 2165 | c_parser_asm_definition (c_parser *parser) |
| 2166 | { |
| 2167 | tree asm_str = c_parser_simple_asm_expr (parser); |
| 2168 | if (asm_str) |
| 2169 | symtab->finalize_toplevel_asm (asm_str); |
| 2170 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>" ); |
| 2171 | } |
| 2172 | |
| 2173 | /* Parse a static assertion (C11 6.7.10). |
| 2174 | |
| 2175 | static_assert-declaration: |
| 2176 | static_assert-declaration-no-semi ; |
| 2177 | */ |
| 2178 | |
| 2179 | static void |
| 2180 | c_parser_static_assert_declaration (c_parser *parser) |
| 2181 | { |
| 2182 | c_parser_static_assert_declaration_no_semi (parser); |
| 2183 | if (parser->error |
| 2184 | || !c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>" )) |
| 2185 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 2186 | } |
| 2187 | |
| 2188 | /* Parse a static assertion (C11 6.7.10), without the trailing |
| 2189 | semicolon. |
| 2190 | |
| 2191 | static_assert-declaration-no-semi: |
| 2192 | _Static_assert ( constant-expression , string-literal ) |
| 2193 | */ |
| 2194 | |
| 2195 | static void |
| 2196 | c_parser_static_assert_declaration_no_semi (c_parser *parser) |
| 2197 | { |
| 2198 | location_t assert_loc, value_loc; |
| 2199 | tree value; |
| 2200 | tree string; |
| 2201 | |
| 2202 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)); |
| 2203 | assert_loc = c_parser_peek_token (parser)->location; |
| 2204 | if (flag_isoc99) |
| 2205 | pedwarn_c99 (assert_loc, OPT_Wpedantic, |
| 2206 | "ISO C99 does not support %<_Static_assert%>" ); |
| 2207 | else |
| 2208 | pedwarn_c99 (assert_loc, OPT_Wpedantic, |
| 2209 | "ISO C90 does not support %<_Static_assert%>" ); |
| 2210 | c_parser_consume_token (parser); |
| 2211 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 2212 | return; |
| 2213 | location_t value_tok_loc = c_parser_peek_token (parser)->location; |
| 2214 | value = c_parser_expr_no_commas (parser, NULL).value; |
| 2215 | value_loc = EXPR_LOC_OR_LOC (value, value_tok_loc); |
| 2216 | parser->lex_untranslated_string = true; |
| 2217 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>" )) |
| 2218 | { |
| 2219 | parser->lex_untranslated_string = false; |
| 2220 | return; |
| 2221 | } |
| 2222 | switch (c_parser_peek_token (parser)->type) |
| 2223 | { |
| 2224 | case CPP_STRING: |
| 2225 | case CPP_STRING16: |
| 2226 | case CPP_STRING32: |
| 2227 | case CPP_WSTRING: |
| 2228 | case CPP_UTF8STRING: |
| 2229 | string = c_parser_peek_token (parser)->value; |
| 2230 | c_parser_consume_token (parser); |
| 2231 | parser->lex_untranslated_string = false; |
| 2232 | break; |
| 2233 | default: |
| 2234 | c_parser_error (parser, "expected string literal" ); |
| 2235 | parser->lex_untranslated_string = false; |
| 2236 | return; |
| 2237 | } |
| 2238 | c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 2239 | |
| 2240 | if (!INTEGRAL_TYPE_P (TREE_TYPE (value))) |
| 2241 | { |
| 2242 | error_at (value_loc, "expression in static assertion is not an integer" ); |
| 2243 | return; |
| 2244 | } |
| 2245 | if (TREE_CODE (value) != INTEGER_CST) |
| 2246 | { |
| 2247 | value = c_fully_fold (value, false, NULL); |
| 2248 | /* Strip no-op conversions. */ |
| 2249 | STRIP_TYPE_NOPS (value); |
| 2250 | if (TREE_CODE (value) == INTEGER_CST) |
| 2251 | pedwarn (value_loc, OPT_Wpedantic, "expression in static assertion " |
| 2252 | "is not an integer constant expression" ); |
| 2253 | } |
| 2254 | if (TREE_CODE (value) != INTEGER_CST) |
| 2255 | { |
| 2256 | error_at (value_loc, "expression in static assertion is not constant" ); |
| 2257 | return; |
| 2258 | } |
| 2259 | constant_expression_warning (value); |
| 2260 | if (integer_zerop (value)) |
| 2261 | error_at (assert_loc, "static assertion failed: %E" , string); |
| 2262 | } |
| 2263 | |
| 2264 | /* Parse some declaration specifiers (possibly none) (C90 6.5, C99 |
| 2265 | 6.7, C11 6.7), adding them to SPECS (which may already include some). |
| 2266 | Storage class specifiers are accepted iff SCSPEC_OK; type |
| 2267 | specifiers are accepted iff TYPESPEC_OK; alignment specifiers are |
| 2268 | accepted iff ALIGNSPEC_OK; attributes are accepted at the start |
| 2269 | iff START_ATTR_OK; __auto_type is accepted iff AUTO_TYPE_OK. |
| 2270 | |
| 2271 | declaration-specifiers: |
| 2272 | storage-class-specifier declaration-specifiers[opt] |
| 2273 | type-specifier declaration-specifiers[opt] |
| 2274 | type-qualifier declaration-specifiers[opt] |
| 2275 | function-specifier declaration-specifiers[opt] |
| 2276 | alignment-specifier declaration-specifiers[opt] |
| 2277 | |
| 2278 | Function specifiers (inline) are from C99, and are currently |
| 2279 | handled as storage class specifiers, as is __thread. Alignment |
| 2280 | specifiers are from C11. |
| 2281 | |
| 2282 | C90 6.5.1, C99 6.7.1, C11 6.7.1: |
| 2283 | storage-class-specifier: |
| 2284 | typedef |
| 2285 | extern |
| 2286 | static |
| 2287 | auto |
| 2288 | register |
| 2289 | _Thread_local |
| 2290 | |
| 2291 | (_Thread_local is new in C11.) |
| 2292 | |
| 2293 | C99 6.7.4, C11 6.7.4: |
| 2294 | function-specifier: |
| 2295 | inline |
| 2296 | _Noreturn |
| 2297 | |
| 2298 | (_Noreturn is new in C11.) |
| 2299 | |
| 2300 | C90 6.5.2, C99 6.7.2, C11 6.7.2: |
| 2301 | type-specifier: |
| 2302 | void |
| 2303 | char |
| 2304 | short |
| 2305 | int |
| 2306 | long |
| 2307 | float |
| 2308 | double |
| 2309 | signed |
| 2310 | unsigned |
| 2311 | _Bool |
| 2312 | _Complex |
| 2313 | [_Imaginary removed in C99 TC2] |
| 2314 | struct-or-union-specifier |
| 2315 | enum-specifier |
| 2316 | typedef-name |
| 2317 | atomic-type-specifier |
| 2318 | |
| 2319 | (_Bool and _Complex are new in C99.) |
| 2320 | (atomic-type-specifier is new in C11.) |
| 2321 | |
| 2322 | C90 6.5.3, C99 6.7.3, C11 6.7.3: |
| 2323 | |
| 2324 | type-qualifier: |
| 2325 | const |
| 2326 | restrict |
| 2327 | volatile |
| 2328 | address-space-qualifier |
| 2329 | _Atomic |
| 2330 | |
| 2331 | (restrict is new in C99.) |
| 2332 | (_Atomic is new in C11.) |
| 2333 | |
| 2334 | GNU extensions: |
| 2335 | |
| 2336 | declaration-specifiers: |
| 2337 | attributes declaration-specifiers[opt] |
| 2338 | |
| 2339 | type-qualifier: |
| 2340 | address-space |
| 2341 | |
| 2342 | address-space: |
| 2343 | identifier recognized by the target |
| 2344 | |
| 2345 | storage-class-specifier: |
| 2346 | __thread |
| 2347 | |
| 2348 | type-specifier: |
| 2349 | typeof-specifier |
| 2350 | __auto_type |
| 2351 | __intN |
| 2352 | _Decimal32 |
| 2353 | _Decimal64 |
| 2354 | _Decimal128 |
| 2355 | _Fract |
| 2356 | _Accum |
| 2357 | _Sat |
| 2358 | |
| 2359 | (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037: |
| 2360 | http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf) |
| 2361 | |
| 2362 | atomic-type-specifier |
| 2363 | _Atomic ( type-name ) |
| 2364 | |
| 2365 | Objective-C: |
| 2366 | |
| 2367 | type-specifier: |
| 2368 | class-name objc-protocol-refs[opt] |
| 2369 | typedef-name objc-protocol-refs |
| 2370 | objc-protocol-refs |
| 2371 | */ |
| 2372 | |
| 2373 | void |
| 2374 | c_parser_declspecs (c_parser *parser, struct c_declspecs *specs, |
| 2375 | bool scspec_ok, bool typespec_ok, bool start_attr_ok, |
| 2376 | bool alignspec_ok, bool auto_type_ok, |
| 2377 | enum c_lookahead_kind la) |
| 2378 | { |
| 2379 | bool attrs_ok = start_attr_ok; |
| 2380 | bool seen_type = specs->typespec_kind != ctsk_none; |
| 2381 | |
| 2382 | if (!typespec_ok) |
| 2383 | gcc_assert (la == cla_prefer_id); |
| 2384 | |
| 2385 | while (c_parser_next_token_is (parser, CPP_NAME) |
| 2386 | || c_parser_next_token_is (parser, CPP_KEYWORD) |
| 2387 | || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS))) |
| 2388 | { |
| 2389 | struct c_typespec t; |
| 2390 | tree attrs; |
| 2391 | tree align; |
| 2392 | location_t loc = c_parser_peek_token (parser)->location; |
| 2393 | |
| 2394 | /* If we cannot accept a type, exit if the next token must start |
| 2395 | one. Also, if we already have seen a tagged definition, |
| 2396 | a typename would be an error anyway and likely the user |
| 2397 | has simply forgotten a semicolon, so we exit. */ |
| 2398 | if ((!typespec_ok || specs->typespec_kind == ctsk_tagdef) |
| 2399 | && c_parser_next_tokens_start_typename (parser, la) |
| 2400 | && !c_parser_next_token_is_qualifier (parser)) |
| 2401 | break; |
| 2402 | |
| 2403 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 2404 | { |
| 2405 | c_token *name_token = c_parser_peek_token (parser); |
| 2406 | tree value = name_token->value; |
| 2407 | c_id_kind kind = name_token->id_kind; |
| 2408 | |
| 2409 | if (kind == C_ID_ADDRSPACE) |
| 2410 | { |
| 2411 | addr_space_t as |
| 2412 | = name_token->keyword - RID_FIRST_ADDR_SPACE; |
| 2413 | declspecs_add_addrspace (name_token->location, specs, as); |
| 2414 | c_parser_consume_token (parser); |
| 2415 | attrs_ok = true; |
| 2416 | continue; |
| 2417 | } |
| 2418 | |
| 2419 | gcc_assert (!c_parser_next_token_is_qualifier (parser)); |
| 2420 | |
| 2421 | /* If we cannot accept a type, and the next token must start one, |
| 2422 | exit. Do the same if we already have seen a tagged definition, |
| 2423 | since it would be an error anyway and likely the user has simply |
| 2424 | forgotten a semicolon. */ |
| 2425 | if (seen_type || !c_parser_next_tokens_start_typename (parser, la)) |
| 2426 | break; |
| 2427 | |
| 2428 | /* Now at an unknown typename (C_ID_ID), a C_ID_TYPENAME or |
| 2429 | a C_ID_CLASSNAME. */ |
| 2430 | c_parser_consume_token (parser); |
| 2431 | seen_type = true; |
| 2432 | attrs_ok = true; |
| 2433 | if (kind == C_ID_ID) |
| 2434 | { |
| 2435 | error_at (loc, "unknown type name %qE" , value); |
| 2436 | t.kind = ctsk_typedef; |
| 2437 | t.spec = error_mark_node; |
| 2438 | } |
| 2439 | else if (kind == C_ID_TYPENAME |
| 2440 | && (!c_dialect_objc () |
| 2441 | || c_parser_next_token_is_not (parser, CPP_LESS))) |
| 2442 | { |
| 2443 | t.kind = ctsk_typedef; |
| 2444 | /* For a typedef name, record the meaning, not the name. |
| 2445 | In case of 'foo foo, bar;'. */ |
| 2446 | t.spec = lookup_name (value); |
| 2447 | } |
| 2448 | else |
| 2449 | { |
| 2450 | tree proto = NULL_TREE; |
| 2451 | gcc_assert (c_dialect_objc ()); |
| 2452 | t.kind = ctsk_objc; |
| 2453 | if (c_parser_next_token_is (parser, CPP_LESS)) |
| 2454 | proto = c_parser_objc_protocol_refs (parser); |
| 2455 | t.spec = objc_get_protocol_qualified_type (value, proto); |
| 2456 | } |
| 2457 | t.expr = NULL_TREE; |
| 2458 | t.expr_const_operands = true; |
| 2459 | declspecs_add_type (name_token->location, specs, t); |
| 2460 | continue; |
| 2461 | } |
| 2462 | if (c_parser_next_token_is (parser, CPP_LESS)) |
| 2463 | { |
| 2464 | /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" - |
| 2465 | nisse@lysator.liu.se. */ |
| 2466 | tree proto; |
| 2467 | gcc_assert (c_dialect_objc ()); |
| 2468 | if (!typespec_ok || seen_type) |
| 2469 | break; |
| 2470 | proto = c_parser_objc_protocol_refs (parser); |
| 2471 | t.kind = ctsk_objc; |
| 2472 | t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto); |
| 2473 | t.expr = NULL_TREE; |
| 2474 | t.expr_const_operands = true; |
| 2475 | declspecs_add_type (loc, specs, t); |
| 2476 | continue; |
| 2477 | } |
| 2478 | gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD)); |
| 2479 | switch (c_parser_peek_token (parser)->keyword) |
| 2480 | { |
| 2481 | case RID_STATIC: |
| 2482 | case RID_EXTERN: |
| 2483 | case RID_REGISTER: |
| 2484 | case RID_TYPEDEF: |
| 2485 | case RID_INLINE: |
| 2486 | case RID_NORETURN: |
| 2487 | case RID_AUTO: |
| 2488 | case RID_THREAD: |
| 2489 | if (!scspec_ok) |
| 2490 | goto out; |
| 2491 | attrs_ok = true; |
| 2492 | /* TODO: Distinguish between function specifiers (inline, noreturn) |
| 2493 | and storage class specifiers, either here or in |
| 2494 | declspecs_add_scspec. */ |
| 2495 | declspecs_add_scspec (loc, specs, |
| 2496 | c_parser_peek_token (parser)->value); |
| 2497 | c_parser_consume_token (parser); |
| 2498 | break; |
| 2499 | case RID_AUTO_TYPE: |
| 2500 | if (!auto_type_ok) |
| 2501 | goto out; |
| 2502 | /* Fall through. */ |
| 2503 | case RID_UNSIGNED: |
| 2504 | case RID_LONG: |
| 2505 | case RID_SHORT: |
| 2506 | case RID_SIGNED: |
| 2507 | case RID_COMPLEX: |
| 2508 | case RID_INT: |
| 2509 | case RID_CHAR: |
| 2510 | case RID_FLOAT: |
| 2511 | case RID_DOUBLE: |
| 2512 | case RID_VOID: |
| 2513 | case RID_DFLOAT32: |
| 2514 | case RID_DFLOAT64: |
| 2515 | case RID_DFLOAT128: |
| 2516 | CASE_RID_FLOATN_NX: |
| 2517 | case RID_BOOL: |
| 2518 | case RID_FRACT: |
| 2519 | case RID_ACCUM: |
| 2520 | case RID_SAT: |
| 2521 | case RID_INT_N_0: |
| 2522 | case RID_INT_N_1: |
| 2523 | case RID_INT_N_2: |
| 2524 | case RID_INT_N_3: |
| 2525 | if (!typespec_ok) |
| 2526 | goto out; |
| 2527 | attrs_ok = true; |
| 2528 | seen_type = true; |
| 2529 | if (c_dialect_objc ()) |
| 2530 | parser->objc_need_raw_identifier = true; |
| 2531 | t.kind = ctsk_resword; |
| 2532 | t.spec = c_parser_peek_token (parser)->value; |
| 2533 | t.expr = NULL_TREE; |
| 2534 | t.expr_const_operands = true; |
| 2535 | declspecs_add_type (loc, specs, t); |
| 2536 | c_parser_consume_token (parser); |
| 2537 | break; |
| 2538 | case RID_ENUM: |
| 2539 | if (!typespec_ok) |
| 2540 | goto out; |
| 2541 | attrs_ok = true; |
| 2542 | seen_type = true; |
| 2543 | t = c_parser_enum_specifier (parser); |
| 2544 | invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec); |
| 2545 | declspecs_add_type (loc, specs, t); |
| 2546 | break; |
| 2547 | case RID_STRUCT: |
| 2548 | case RID_UNION: |
| 2549 | if (!typespec_ok) |
| 2550 | goto out; |
| 2551 | attrs_ok = true; |
| 2552 | seen_type = true; |
| 2553 | t = c_parser_struct_or_union_specifier (parser); |
| 2554 | invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec); |
| 2555 | declspecs_add_type (loc, specs, t); |
| 2556 | break; |
| 2557 | case RID_TYPEOF: |
| 2558 | /* ??? The old parser rejected typeof after other type |
| 2559 | specifiers, but is a syntax error the best way of |
| 2560 | handling this? */ |
| 2561 | if (!typespec_ok || seen_type) |
| 2562 | goto out; |
| 2563 | attrs_ok = true; |
| 2564 | seen_type = true; |
| 2565 | t = c_parser_typeof_specifier (parser); |
| 2566 | declspecs_add_type (loc, specs, t); |
| 2567 | break; |
| 2568 | case RID_ATOMIC: |
| 2569 | /* C parser handling of Objective-C constructs needs |
| 2570 | checking for correct lvalue-to-rvalue conversions, and |
| 2571 | the code in build_modify_expr handling various |
| 2572 | Objective-C cases, and that in build_unary_op handling |
| 2573 | Objective-C cases for increment / decrement, also needs |
| 2574 | updating; uses of TYPE_MAIN_VARIANT in objc_compare_types |
| 2575 | and objc_types_are_equivalent may also need updates. */ |
| 2576 | if (c_dialect_objc ()) |
| 2577 | sorry ("%<_Atomic%> in Objective-C" ); |
| 2578 | if (flag_isoc99) |
| 2579 | pedwarn_c99 (loc, OPT_Wpedantic, |
| 2580 | "ISO C99 does not support the %<_Atomic%> qualifier" ); |
| 2581 | else |
| 2582 | pedwarn_c99 (loc, OPT_Wpedantic, |
| 2583 | "ISO C90 does not support the %<_Atomic%> qualifier" ); |
| 2584 | attrs_ok = true; |
| 2585 | tree value; |
| 2586 | value = c_parser_peek_token (parser)->value; |
| 2587 | c_parser_consume_token (parser); |
| 2588 | if (typespec_ok && c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 2589 | { |
| 2590 | /* _Atomic ( type-name ). */ |
| 2591 | seen_type = true; |
| 2592 | c_parser_consume_token (parser); |
| 2593 | struct c_type_name *type = c_parser_type_name (parser); |
| 2594 | t.kind = ctsk_typeof; |
| 2595 | t.spec = error_mark_node; |
| 2596 | t.expr = NULL_TREE; |
| 2597 | t.expr_const_operands = true; |
| 2598 | if (type != NULL) |
| 2599 | t.spec = groktypename (type, &t.expr, |
| 2600 | &t.expr_const_operands); |
| 2601 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 2602 | "expected %<)%>" ); |
| 2603 | if (t.spec != error_mark_node) |
| 2604 | { |
| 2605 | if (TREE_CODE (t.spec) == ARRAY_TYPE) |
| 2606 | error_at (loc, "%<_Atomic%>-qualified array type" ); |
| 2607 | else if (TREE_CODE (t.spec) == FUNCTION_TYPE) |
| 2608 | error_at (loc, "%<_Atomic%>-qualified function type" ); |
| 2609 | else if (TYPE_QUALS (t.spec) != TYPE_UNQUALIFIED) |
| 2610 | error_at (loc, "%<_Atomic%> applied to a qualified type" ); |
| 2611 | else |
| 2612 | t.spec = c_build_qualified_type (t.spec, TYPE_QUAL_ATOMIC); |
| 2613 | } |
| 2614 | declspecs_add_type (loc, specs, t); |
| 2615 | } |
| 2616 | else |
| 2617 | declspecs_add_qual (loc, specs, value); |
| 2618 | break; |
| 2619 | case RID_CONST: |
| 2620 | case RID_VOLATILE: |
| 2621 | case RID_RESTRICT: |
| 2622 | attrs_ok = true; |
| 2623 | declspecs_add_qual (loc, specs, c_parser_peek_token (parser)->value); |
| 2624 | c_parser_consume_token (parser); |
| 2625 | break; |
| 2626 | case RID_ATTRIBUTE: |
| 2627 | if (!attrs_ok) |
| 2628 | goto out; |
| 2629 | attrs = c_parser_attributes (parser); |
| 2630 | declspecs_add_attrs (loc, specs, attrs); |
| 2631 | break; |
| 2632 | case RID_ALIGNAS: |
| 2633 | if (!alignspec_ok) |
| 2634 | goto out; |
| 2635 | align = c_parser_alignas_specifier (parser); |
| 2636 | declspecs_add_alignas (loc, specs, align); |
| 2637 | break; |
| 2638 | case RID_GIMPLE: |
| 2639 | if (! flag_gimple) |
| 2640 | error_at (loc, "%<__GIMPLE%> only valid with -fgimple" ); |
| 2641 | c_parser_consume_token (parser); |
| 2642 | specs->gimple_p = true; |
| 2643 | specs->locations[cdw_gimple] = loc; |
| 2644 | specs->gimple_or_rtl_pass = c_parser_gimple_or_rtl_pass_list (parser); |
| 2645 | break; |
| 2646 | case RID_RTL: |
| 2647 | c_parser_consume_token (parser); |
| 2648 | specs->rtl_p = true; |
| 2649 | specs->locations[cdw_rtl] = loc; |
| 2650 | specs->gimple_or_rtl_pass = c_parser_gimple_or_rtl_pass_list (parser); |
| 2651 | break; |
| 2652 | default: |
| 2653 | goto out; |
| 2654 | } |
| 2655 | } |
| 2656 | out: ; |
| 2657 | } |
| 2658 | |
| 2659 | /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2, C11 6.7.2.2). |
| 2660 | |
| 2661 | enum-specifier: |
| 2662 | enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt] |
| 2663 | enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt] |
| 2664 | enum attributes[opt] identifier |
| 2665 | |
| 2666 | The form with trailing comma is new in C99. The forms with |
| 2667 | attributes are GNU extensions. In GNU C, we accept any expression |
| 2668 | without commas in the syntax (assignment expressions, not just |
| 2669 | conditional expressions); assignment expressions will be diagnosed |
| 2670 | as non-constant. |
| 2671 | |
| 2672 | enumerator-list: |
| 2673 | enumerator |
| 2674 | enumerator-list , enumerator |
| 2675 | |
| 2676 | enumerator: |
| 2677 | enumeration-constant |
| 2678 | enumeration-constant = constant-expression |
| 2679 | |
| 2680 | GNU Extensions: |
| 2681 | |
| 2682 | enumerator: |
| 2683 | enumeration-constant attributes[opt] |
| 2684 | enumeration-constant attributes[opt] = constant-expression |
| 2685 | |
| 2686 | */ |
| 2687 | |
| 2688 | static struct c_typespec |
| 2689 | c_parser_enum_specifier (c_parser *parser) |
| 2690 | { |
| 2691 | struct c_typespec ret; |
| 2692 | tree attrs; |
| 2693 | tree ident = NULL_TREE; |
| 2694 | location_t enum_loc; |
| 2695 | location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
| 2696 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM)); |
| 2697 | c_parser_consume_token (parser); |
| 2698 | attrs = c_parser_attributes (parser); |
| 2699 | enum_loc = c_parser_peek_token (parser)->location; |
| 2700 | /* Set the location in case we create a decl now. */ |
| 2701 | c_parser_set_source_position_from_token (c_parser_peek_token (parser)); |
| 2702 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 2703 | { |
| 2704 | ident = c_parser_peek_token (parser)->value; |
| 2705 | ident_loc = c_parser_peek_token (parser)->location; |
| 2706 | enum_loc = ident_loc; |
| 2707 | c_parser_consume_token (parser); |
| 2708 | } |
| 2709 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 2710 | { |
| 2711 | /* Parse an enum definition. */ |
| 2712 | struct c_enum_contents the_enum; |
| 2713 | tree type; |
| 2714 | tree postfix_attrs; |
| 2715 | /* We chain the enumerators in reverse order, then put them in |
| 2716 | forward order at the end. */ |
| 2717 | tree values; |
| 2718 | timevar_push (TV_PARSE_ENUM); |
| 2719 | type = start_enum (enum_loc, &the_enum, ident); |
| 2720 | values = NULL_TREE; |
| 2721 | c_parser_consume_token (parser); |
| 2722 | while (true) |
| 2723 | { |
| 2724 | tree enum_id; |
| 2725 | tree enum_value; |
| 2726 | tree enum_decl; |
| 2727 | bool seen_comma; |
| 2728 | c_token *token; |
| 2729 | location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
| 2730 | location_t decl_loc, value_loc; |
| 2731 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 2732 | { |
| 2733 | /* Give a nicer error for "enum {}". */ |
| 2734 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE) |
| 2735 | && !parser->error) |
| 2736 | { |
| 2737 | error_at (c_parser_peek_token (parser)->location, |
| 2738 | "empty enum is invalid" ); |
| 2739 | parser->error = true; |
| 2740 | } |
| 2741 | else |
| 2742 | c_parser_error (parser, "expected identifier" ); |
| 2743 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); |
| 2744 | values = error_mark_node; |
| 2745 | break; |
| 2746 | } |
| 2747 | token = c_parser_peek_token (parser); |
| 2748 | enum_id = token->value; |
| 2749 | /* Set the location in case we create a decl now. */ |
| 2750 | c_parser_set_source_position_from_token (token); |
| 2751 | decl_loc = value_loc = token->location; |
| 2752 | c_parser_consume_token (parser); |
| 2753 | /* Parse any specified attributes. */ |
| 2754 | tree enum_attrs = c_parser_attributes (parser); |
| 2755 | if (c_parser_next_token_is (parser, CPP_EQ)) |
| 2756 | { |
| 2757 | c_parser_consume_token (parser); |
| 2758 | value_loc = c_parser_peek_token (parser)->location; |
| 2759 | enum_value = c_parser_expr_no_commas (parser, NULL).value; |
| 2760 | } |
| 2761 | else |
| 2762 | enum_value = NULL_TREE; |
| 2763 | enum_decl = build_enumerator (decl_loc, value_loc, |
| 2764 | &the_enum, enum_id, enum_value); |
| 2765 | if (enum_attrs) |
| 2766 | decl_attributes (&TREE_PURPOSE (enum_decl), enum_attrs, 0); |
| 2767 | TREE_CHAIN (enum_decl) = values; |
| 2768 | values = enum_decl; |
| 2769 | seen_comma = false; |
| 2770 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 2771 | { |
| 2772 | comma_loc = c_parser_peek_token (parser)->location; |
| 2773 | seen_comma = true; |
| 2774 | c_parser_consume_token (parser); |
| 2775 | } |
| 2776 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 2777 | { |
| 2778 | if (seen_comma) |
| 2779 | pedwarn_c90 (comma_loc, OPT_Wpedantic, |
| 2780 | "comma at end of enumerator list" ); |
| 2781 | c_parser_consume_token (parser); |
| 2782 | break; |
| 2783 | } |
| 2784 | if (!seen_comma) |
| 2785 | { |
| 2786 | c_parser_error (parser, "expected %<,%> or %<}%>" ); |
| 2787 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); |
| 2788 | values = error_mark_node; |
| 2789 | break; |
| 2790 | } |
| 2791 | } |
| 2792 | postfix_attrs = c_parser_attributes (parser); |
| 2793 | ret.spec = finish_enum (type, nreverse (values), |
| 2794 | chainon (attrs, postfix_attrs)); |
| 2795 | ret.kind = ctsk_tagdef; |
| 2796 | ret.expr = NULL_TREE; |
| 2797 | ret.expr_const_operands = true; |
| 2798 | timevar_pop (TV_PARSE_ENUM); |
| 2799 | return ret; |
| 2800 | } |
| 2801 | else if (!ident) |
| 2802 | { |
| 2803 | c_parser_error (parser, "expected %<{%>" ); |
| 2804 | ret.spec = error_mark_node; |
| 2805 | ret.kind = ctsk_tagref; |
| 2806 | ret.expr = NULL_TREE; |
| 2807 | ret.expr_const_operands = true; |
| 2808 | return ret; |
| 2809 | } |
| 2810 | ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident); |
| 2811 | /* In ISO C, enumerated types can be referred to only if already |
| 2812 | defined. */ |
| 2813 | if (pedantic && !COMPLETE_TYPE_P (ret.spec)) |
| 2814 | { |
| 2815 | gcc_assert (ident); |
| 2816 | pedwarn (enum_loc, OPT_Wpedantic, |
| 2817 | "ISO C forbids forward references to %<enum%> types" ); |
| 2818 | } |
| 2819 | return ret; |
| 2820 | } |
| 2821 | |
| 2822 | /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1). |
| 2823 | |
| 2824 | struct-or-union-specifier: |
| 2825 | struct-or-union attributes[opt] identifier[opt] |
| 2826 | { struct-contents } attributes[opt] |
| 2827 | struct-or-union attributes[opt] identifier |
| 2828 | |
| 2829 | struct-contents: |
| 2830 | struct-declaration-list |
| 2831 | |
| 2832 | struct-declaration-list: |
| 2833 | struct-declaration ; |
| 2834 | struct-declaration-list struct-declaration ; |
| 2835 | |
| 2836 | GNU extensions: |
| 2837 | |
| 2838 | struct-contents: |
| 2839 | empty |
| 2840 | struct-declaration |
| 2841 | struct-declaration-list struct-declaration |
| 2842 | |
| 2843 | struct-declaration-list: |
| 2844 | struct-declaration-list ; |
| 2845 | ; |
| 2846 | |
| 2847 | (Note that in the syntax here, unlike that in ISO C, the semicolons |
| 2848 | are included here rather than in struct-declaration, in order to |
| 2849 | describe the syntax with extra semicolons and missing semicolon at |
| 2850 | end.) |
| 2851 | |
| 2852 | Objective-C: |
| 2853 | |
| 2854 | struct-declaration-list: |
| 2855 | @defs ( class-name ) |
| 2856 | |
| 2857 | (Note this does not include a trailing semicolon, but can be |
| 2858 | followed by further declarations, and gets a pedwarn-if-pedantic |
| 2859 | when followed by a semicolon.) */ |
| 2860 | |
| 2861 | static struct c_typespec |
| 2862 | c_parser_struct_or_union_specifier (c_parser *parser) |
| 2863 | { |
| 2864 | struct c_typespec ret; |
| 2865 | tree attrs; |
| 2866 | tree ident = NULL_TREE; |
| 2867 | location_t struct_loc; |
| 2868 | location_t ident_loc = UNKNOWN_LOCATION; |
| 2869 | enum tree_code code; |
| 2870 | switch (c_parser_peek_token (parser)->keyword) |
| 2871 | { |
| 2872 | case RID_STRUCT: |
| 2873 | code = RECORD_TYPE; |
| 2874 | break; |
| 2875 | case RID_UNION: |
| 2876 | code = UNION_TYPE; |
| 2877 | break; |
| 2878 | default: |
| 2879 | gcc_unreachable (); |
| 2880 | } |
| 2881 | struct_loc = c_parser_peek_token (parser)->location; |
| 2882 | c_parser_consume_token (parser); |
| 2883 | attrs = c_parser_attributes (parser); |
| 2884 | |
| 2885 | /* Set the location in case we create a decl now. */ |
| 2886 | c_parser_set_source_position_from_token (c_parser_peek_token (parser)); |
| 2887 | |
| 2888 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 2889 | { |
| 2890 | ident = c_parser_peek_token (parser)->value; |
| 2891 | ident_loc = c_parser_peek_token (parser)->location; |
| 2892 | struct_loc = ident_loc; |
| 2893 | c_parser_consume_token (parser); |
| 2894 | } |
| 2895 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 2896 | { |
| 2897 | /* Parse a struct or union definition. Start the scope of the |
| 2898 | tag before parsing components. */ |
| 2899 | struct c_struct_parse_info *struct_info; |
| 2900 | tree type = start_struct (struct_loc, code, ident, &struct_info); |
| 2901 | tree postfix_attrs; |
| 2902 | /* We chain the components in reverse order, then put them in |
| 2903 | forward order at the end. Each struct-declaration may |
| 2904 | declare multiple components (comma-separated), so we must use |
| 2905 | chainon to join them, although when parsing each |
| 2906 | struct-declaration we can use TREE_CHAIN directly. |
| 2907 | |
| 2908 | The theory behind all this is that there will be more |
| 2909 | semicolon separated fields than comma separated fields, and |
| 2910 | so we'll be minimizing the number of node traversals required |
| 2911 | by chainon. */ |
| 2912 | tree contents; |
| 2913 | timevar_push (TV_PARSE_STRUCT); |
| 2914 | contents = NULL_TREE; |
| 2915 | c_parser_consume_token (parser); |
| 2916 | /* Handle the Objective-C @defs construct, |
| 2917 | e.g. foo(sizeof(struct{ @defs(ClassName) }));. */ |
| 2918 | if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS)) |
| 2919 | { |
| 2920 | tree name; |
| 2921 | gcc_assert (c_dialect_objc ()); |
| 2922 | c_parser_consume_token (parser); |
| 2923 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 2924 | goto end_at_defs; |
| 2925 | if (c_parser_next_token_is (parser, CPP_NAME) |
| 2926 | && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME) |
| 2927 | { |
| 2928 | name = c_parser_peek_token (parser)->value; |
| 2929 | c_parser_consume_token (parser); |
| 2930 | } |
| 2931 | else |
| 2932 | { |
| 2933 | c_parser_error (parser, "expected class name" ); |
| 2934 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 2935 | goto end_at_defs; |
| 2936 | } |
| 2937 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 2938 | "expected %<)%>" ); |
| 2939 | contents = nreverse (objc_get_class_ivars (name)); |
| 2940 | } |
| 2941 | end_at_defs: |
| 2942 | /* Parse the struct-declarations and semicolons. Problems with |
| 2943 | semicolons are diagnosed here; empty structures are diagnosed |
| 2944 | elsewhere. */ |
| 2945 | while (true) |
| 2946 | { |
| 2947 | tree decls; |
| 2948 | /* Parse any stray semicolon. */ |
| 2949 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 2950 | { |
| 2951 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
| 2952 | "extra semicolon in struct or union specified" ); |
| 2953 | c_parser_consume_token (parser); |
| 2954 | continue; |
| 2955 | } |
| 2956 | /* Stop if at the end of the struct or union contents. */ |
| 2957 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 2958 | { |
| 2959 | c_parser_consume_token (parser); |
| 2960 | break; |
| 2961 | } |
| 2962 | /* Accept #pragmas at struct scope. */ |
| 2963 | if (c_parser_next_token_is (parser, CPP_PRAGMA)) |
| 2964 | { |
| 2965 | c_parser_pragma (parser, pragma_struct, NULL); |
| 2966 | continue; |
| 2967 | } |
| 2968 | /* Parse some comma-separated declarations, but not the |
| 2969 | trailing semicolon if any. */ |
| 2970 | decls = c_parser_struct_declaration (parser); |
| 2971 | contents = chainon (decls, contents); |
| 2972 | /* If no semicolon follows, either we have a parse error or |
| 2973 | are at the end of the struct or union and should |
| 2974 | pedwarn. */ |
| 2975 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 2976 | c_parser_consume_token (parser); |
| 2977 | else |
| 2978 | { |
| 2979 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 2980 | pedwarn (c_parser_peek_token (parser)->location, 0, |
| 2981 | "no semicolon at end of struct or union" ); |
| 2982 | else if (parser->error |
| 2983 | || !c_parser_next_token_starts_declspecs (parser)) |
| 2984 | { |
| 2985 | c_parser_error (parser, "expected %<;%>" ); |
| 2986 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); |
| 2987 | break; |
| 2988 | } |
| 2989 | |
| 2990 | /* If we come here, we have already emitted an error |
| 2991 | for an expected `;', identifier or `(', and we also |
| 2992 | recovered already. Go on with the next field. */ |
| 2993 | } |
| 2994 | } |
| 2995 | postfix_attrs = c_parser_attributes (parser); |
| 2996 | ret.spec = finish_struct (struct_loc, type, nreverse (contents), |
| 2997 | chainon (attrs, postfix_attrs), struct_info); |
| 2998 | ret.kind = ctsk_tagdef; |
| 2999 | ret.expr = NULL_TREE; |
| 3000 | ret.expr_const_operands = true; |
| 3001 | timevar_pop (TV_PARSE_STRUCT); |
| 3002 | return ret; |
| 3003 | } |
| 3004 | else if (!ident) |
| 3005 | { |
| 3006 | c_parser_error (parser, "expected %<{%>" ); |
| 3007 | ret.spec = error_mark_node; |
| 3008 | ret.kind = ctsk_tagref; |
| 3009 | ret.expr = NULL_TREE; |
| 3010 | ret.expr_const_operands = true; |
| 3011 | return ret; |
| 3012 | } |
| 3013 | ret = parser_xref_tag (ident_loc, code, ident); |
| 3014 | return ret; |
| 3015 | } |
| 3016 | |
| 3017 | /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1, C11 6.7.2.1), |
| 3018 | *without* the trailing semicolon. |
| 3019 | |
| 3020 | struct-declaration: |
| 3021 | specifier-qualifier-list struct-declarator-list |
| 3022 | static_assert-declaration-no-semi |
| 3023 | |
| 3024 | specifier-qualifier-list: |
| 3025 | type-specifier specifier-qualifier-list[opt] |
| 3026 | type-qualifier specifier-qualifier-list[opt] |
| 3027 | attributes specifier-qualifier-list[opt] |
| 3028 | |
| 3029 | struct-declarator-list: |
| 3030 | struct-declarator |
| 3031 | struct-declarator-list , attributes[opt] struct-declarator |
| 3032 | |
| 3033 | struct-declarator: |
| 3034 | declarator attributes[opt] |
| 3035 | declarator[opt] : constant-expression attributes[opt] |
| 3036 | |
| 3037 | GNU extensions: |
| 3038 | |
| 3039 | struct-declaration: |
| 3040 | __extension__ struct-declaration |
| 3041 | specifier-qualifier-list |
| 3042 | |
| 3043 | Unlike the ISO C syntax, semicolons are handled elsewhere. The use |
| 3044 | of attributes where shown is a GNU extension. In GNU C, we accept |
| 3045 | any expression without commas in the syntax (assignment |
| 3046 | expressions, not just conditional expressions); assignment |
| 3047 | expressions will be diagnosed as non-constant. */ |
| 3048 | |
| 3049 | static tree |
| 3050 | c_parser_struct_declaration (c_parser *parser) |
| 3051 | { |
| 3052 | struct c_declspecs *specs; |
| 3053 | tree prefix_attrs; |
| 3054 | tree all_prefix_attrs; |
| 3055 | tree decls; |
| 3056 | location_t decl_loc; |
| 3057 | if (c_parser_next_token_is_keyword (parser, RID_EXTENSION)) |
| 3058 | { |
| 3059 | int ext; |
| 3060 | tree decl; |
| 3061 | ext = disable_extension_diagnostics (); |
| 3062 | c_parser_consume_token (parser); |
| 3063 | decl = c_parser_struct_declaration (parser); |
| 3064 | restore_extension_diagnostics (ext); |
| 3065 | return decl; |
| 3066 | } |
| 3067 | if (c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)) |
| 3068 | { |
| 3069 | c_parser_static_assert_declaration_no_semi (parser); |
| 3070 | return NULL_TREE; |
| 3071 | } |
| 3072 | specs = build_null_declspecs (); |
| 3073 | decl_loc = c_parser_peek_token (parser)->location; |
| 3074 | /* Strictly by the standard, we shouldn't allow _Alignas here, |
| 3075 | but it appears to have been intended to allow it there, so |
| 3076 | we're keeping it as it is until WG14 reaches a conclusion |
| 3077 | of N1731. |
| 3078 | <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1731.pdf> */ |
| 3079 | c_parser_declspecs (parser, specs, false, true, true, |
| 3080 | true, false, cla_nonabstract_decl); |
| 3081 | if (parser->error) |
| 3082 | return NULL_TREE; |
| 3083 | if (!specs->declspecs_seen_p) |
| 3084 | { |
| 3085 | c_parser_error (parser, "expected specifier-qualifier-list" ); |
| 3086 | return NULL_TREE; |
| 3087 | } |
| 3088 | finish_declspecs (specs); |
| 3089 | if (c_parser_next_token_is (parser, CPP_SEMICOLON) |
| 3090 | || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 3091 | { |
| 3092 | tree ret; |
| 3093 | if (specs->typespec_kind == ctsk_none) |
| 3094 | { |
| 3095 | pedwarn (decl_loc, OPT_Wpedantic, |
| 3096 | "ISO C forbids member declarations with no members" ); |
| 3097 | shadow_tag_warned (specs, pedantic); |
| 3098 | ret = NULL_TREE; |
| 3099 | } |
| 3100 | else |
| 3101 | { |
| 3102 | /* Support for unnamed structs or unions as members of |
| 3103 | structs or unions (which is [a] useful and [b] supports |
| 3104 | MS P-SDK). */ |
| 3105 | tree attrs = NULL; |
| 3106 | |
| 3107 | ret = grokfield (c_parser_peek_token (parser)->location, |
| 3108 | build_id_declarator (NULL_TREE), specs, |
| 3109 | NULL_TREE, &attrs); |
| 3110 | if (ret) |
| 3111 | decl_attributes (&ret, attrs, 0); |
| 3112 | } |
| 3113 | return ret; |
| 3114 | } |
| 3115 | |
| 3116 | /* Provide better error recovery. Note that a type name here is valid, |
| 3117 | and will be treated as a field name. */ |
| 3118 | if (specs->typespec_kind == ctsk_tagdef |
| 3119 | && TREE_CODE (specs->type) != ENUMERAL_TYPE |
| 3120 | && c_parser_next_token_starts_declspecs (parser) |
| 3121 | && !c_parser_next_token_is (parser, CPP_NAME)) |
| 3122 | { |
| 3123 | c_parser_error (parser, "expected %<;%>, identifier or %<(%>" ); |
| 3124 | parser->error = false; |
| 3125 | return NULL_TREE; |
| 3126 | } |
| 3127 | |
| 3128 | pending_xref_error (); |
| 3129 | prefix_attrs = specs->attrs; |
| 3130 | all_prefix_attrs = prefix_attrs; |
| 3131 | specs->attrs = NULL_TREE; |
| 3132 | decls = NULL_TREE; |
| 3133 | while (true) |
| 3134 | { |
| 3135 | /* Declaring one or more declarators or un-named bit-fields. */ |
| 3136 | struct c_declarator *declarator; |
| 3137 | bool dummy = false; |
| 3138 | if (c_parser_next_token_is (parser, CPP_COLON)) |
| 3139 | declarator = build_id_declarator (NULL_TREE); |
| 3140 | else |
| 3141 | declarator = c_parser_declarator (parser, |
| 3142 | specs->typespec_kind != ctsk_none, |
| 3143 | C_DTR_NORMAL, &dummy); |
| 3144 | if (declarator == NULL) |
| 3145 | { |
| 3146 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 3147 | break; |
| 3148 | } |
| 3149 | if (c_parser_next_token_is (parser, CPP_COLON) |
| 3150 | || c_parser_next_token_is (parser, CPP_COMMA) |
| 3151 | || c_parser_next_token_is (parser, CPP_SEMICOLON) |
| 3152 | || c_parser_next_token_is (parser, CPP_CLOSE_BRACE) |
| 3153 | || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 3154 | { |
| 3155 | tree postfix_attrs = NULL_TREE; |
| 3156 | tree width = NULL_TREE; |
| 3157 | tree d; |
| 3158 | if (c_parser_next_token_is (parser, CPP_COLON)) |
| 3159 | { |
| 3160 | c_parser_consume_token (parser); |
| 3161 | width = c_parser_expr_no_commas (parser, NULL).value; |
| 3162 | } |
| 3163 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 3164 | postfix_attrs = c_parser_attributes (parser); |
| 3165 | d = grokfield (c_parser_peek_token (parser)->location, |
| 3166 | declarator, specs, width, &all_prefix_attrs); |
| 3167 | decl_attributes (&d, chainon (postfix_attrs, |
| 3168 | all_prefix_attrs), 0); |
| 3169 | DECL_CHAIN (d) = decls; |
| 3170 | decls = d; |
| 3171 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 3172 | all_prefix_attrs = chainon (c_parser_attributes (parser), |
| 3173 | prefix_attrs); |
| 3174 | else |
| 3175 | all_prefix_attrs = prefix_attrs; |
| 3176 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 3177 | c_parser_consume_token (parser); |
| 3178 | else if (c_parser_next_token_is (parser, CPP_SEMICOLON) |
| 3179 | || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 3180 | { |
| 3181 | /* Semicolon consumed in caller. */ |
| 3182 | break; |
| 3183 | } |
| 3184 | else |
| 3185 | { |
| 3186 | c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>" ); |
| 3187 | break; |
| 3188 | } |
| 3189 | } |
| 3190 | else |
| 3191 | { |
| 3192 | c_parser_error (parser, |
| 3193 | "expected %<:%>, %<,%>, %<;%>, %<}%> or " |
| 3194 | "%<__attribute__%>" ); |
| 3195 | break; |
| 3196 | } |
| 3197 | } |
| 3198 | return decls; |
| 3199 | } |
| 3200 | |
| 3201 | /* Parse a typeof specifier (a GNU extension). |
| 3202 | |
| 3203 | typeof-specifier: |
| 3204 | typeof ( expression ) |
| 3205 | typeof ( type-name ) |
| 3206 | */ |
| 3207 | |
| 3208 | static struct c_typespec |
| 3209 | c_parser_typeof_specifier (c_parser *parser) |
| 3210 | { |
| 3211 | struct c_typespec ret; |
| 3212 | ret.kind = ctsk_typeof; |
| 3213 | ret.spec = error_mark_node; |
| 3214 | ret.expr = NULL_TREE; |
| 3215 | ret.expr_const_operands = true; |
| 3216 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF)); |
| 3217 | c_parser_consume_token (parser); |
| 3218 | c_inhibit_evaluation_warnings++; |
| 3219 | in_typeof++; |
| 3220 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 3221 | { |
| 3222 | c_inhibit_evaluation_warnings--; |
| 3223 | in_typeof--; |
| 3224 | return ret; |
| 3225 | } |
| 3226 | if (c_parser_next_tokens_start_typename (parser, cla_prefer_id)) |
| 3227 | { |
| 3228 | struct c_type_name *type = c_parser_type_name (parser); |
| 3229 | c_inhibit_evaluation_warnings--; |
| 3230 | in_typeof--; |
| 3231 | if (type != NULL) |
| 3232 | { |
| 3233 | ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands); |
| 3234 | pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE)); |
| 3235 | } |
| 3236 | } |
| 3237 | else |
| 3238 | { |
| 3239 | bool was_vm; |
| 3240 | location_t here = c_parser_peek_token (parser)->location; |
| 3241 | struct c_expr expr = c_parser_expression (parser); |
| 3242 | c_inhibit_evaluation_warnings--; |
| 3243 | in_typeof--; |
| 3244 | if (TREE_CODE (expr.value) == COMPONENT_REF |
| 3245 | && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1))) |
| 3246 | error_at (here, "%<typeof%> applied to a bit-field" ); |
| 3247 | mark_exp_read (expr.value); |
| 3248 | ret.spec = TREE_TYPE (expr.value); |
| 3249 | was_vm = variably_modified_type_p (ret.spec, NULL_TREE); |
| 3250 | /* This is returned with the type so that when the type is |
| 3251 | evaluated, this can be evaluated. */ |
| 3252 | if (was_vm) |
| 3253 | ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands); |
| 3254 | pop_maybe_used (was_vm); |
| 3255 | /* For use in macros such as those in <stdatomic.h>, remove all |
| 3256 | qualifiers from atomic types. (const can be an issue for more macros |
| 3257 | using typeof than just the <stdatomic.h> ones.) */ |
| 3258 | if (ret.spec != error_mark_node && TYPE_ATOMIC (ret.spec)) |
| 3259 | ret.spec = c_build_qualified_type (ret.spec, TYPE_UNQUALIFIED); |
| 3260 | } |
| 3261 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 3262 | return ret; |
| 3263 | } |
| 3264 | |
| 3265 | /* Parse an alignment-specifier. |
| 3266 | |
| 3267 | C11 6.7.5: |
| 3268 | |
| 3269 | alignment-specifier: |
| 3270 | _Alignas ( type-name ) |
| 3271 | _Alignas ( constant-expression ) |
| 3272 | */ |
| 3273 | |
| 3274 | static tree |
| 3275 | c_parser_alignas_specifier (c_parser * parser) |
| 3276 | { |
| 3277 | tree ret = error_mark_node; |
| 3278 | location_t loc = c_parser_peek_token (parser)->location; |
| 3279 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNAS)); |
| 3280 | c_parser_consume_token (parser); |
| 3281 | if (flag_isoc99) |
| 3282 | pedwarn_c99 (loc, OPT_Wpedantic, |
| 3283 | "ISO C99 does not support %<_Alignas%>" ); |
| 3284 | else |
| 3285 | pedwarn_c99 (loc, OPT_Wpedantic, |
| 3286 | "ISO C90 does not support %<_Alignas%>" ); |
| 3287 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 3288 | return ret; |
| 3289 | if (c_parser_next_tokens_start_typename (parser, cla_prefer_id)) |
| 3290 | { |
| 3291 | struct c_type_name *type = c_parser_type_name (parser); |
| 3292 | if (type != NULL) |
| 3293 | ret = c_sizeof_or_alignof_type (loc, groktypename (type, NULL, NULL), |
| 3294 | false, true, 1); |
| 3295 | } |
| 3296 | else |
| 3297 | ret = c_parser_expr_no_commas (parser, NULL).value; |
| 3298 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 3299 | return ret; |
| 3300 | } |
| 3301 | |
| 3302 | /* Parse a declarator, possibly an abstract declarator (C90 6.5.4, |
| 3303 | 6.5.5, C99 6.7.5, 6.7.6, C11 6.7.6, 6.7.7). If TYPE_SEEN_P then |
| 3304 | a typedef name may be redeclared; otherwise it may not. KIND |
| 3305 | indicates which kind of declarator is wanted. Returns a valid |
| 3306 | declarator except in the case of a syntax error in which case NULL is |
| 3307 | returned. *SEEN_ID is set to true if an identifier being declared is |
| 3308 | seen; this is used to diagnose bad forms of abstract array declarators |
| 3309 | and to determine whether an identifier list is syntactically permitted. |
| 3310 | |
| 3311 | declarator: |
| 3312 | pointer[opt] direct-declarator |
| 3313 | |
| 3314 | direct-declarator: |
| 3315 | identifier |
| 3316 | ( attributes[opt] declarator ) |
| 3317 | direct-declarator array-declarator |
| 3318 | direct-declarator ( parameter-type-list ) |
| 3319 | direct-declarator ( identifier-list[opt] ) |
| 3320 | |
| 3321 | pointer: |
| 3322 | * type-qualifier-list[opt] |
| 3323 | * type-qualifier-list[opt] pointer |
| 3324 | |
| 3325 | type-qualifier-list: |
| 3326 | type-qualifier |
| 3327 | attributes |
| 3328 | type-qualifier-list type-qualifier |
| 3329 | type-qualifier-list attributes |
| 3330 | |
| 3331 | array-declarator: |
| 3332 | [ type-qualifier-list[opt] assignment-expression[opt] ] |
| 3333 | [ static type-qualifier-list[opt] assignment-expression ] |
| 3334 | [ type-qualifier-list static assignment-expression ] |
| 3335 | [ type-qualifier-list[opt] * ] |
| 3336 | |
| 3337 | parameter-type-list: |
| 3338 | parameter-list |
| 3339 | parameter-list , ... |
| 3340 | |
| 3341 | parameter-list: |
| 3342 | parameter-declaration |
| 3343 | parameter-list , parameter-declaration |
| 3344 | |
| 3345 | parameter-declaration: |
| 3346 | declaration-specifiers declarator attributes[opt] |
| 3347 | declaration-specifiers abstract-declarator[opt] attributes[opt] |
| 3348 | |
| 3349 | identifier-list: |
| 3350 | identifier |
| 3351 | identifier-list , identifier |
| 3352 | |
| 3353 | abstract-declarator: |
| 3354 | pointer |
| 3355 | pointer[opt] direct-abstract-declarator |
| 3356 | |
| 3357 | direct-abstract-declarator: |
| 3358 | ( attributes[opt] abstract-declarator ) |
| 3359 | direct-abstract-declarator[opt] array-declarator |
| 3360 | direct-abstract-declarator[opt] ( parameter-type-list[opt] ) |
| 3361 | |
| 3362 | GNU extensions: |
| 3363 | |
| 3364 | direct-declarator: |
| 3365 | direct-declarator ( parameter-forward-declarations |
| 3366 | parameter-type-list[opt] ) |
| 3367 | |
| 3368 | direct-abstract-declarator: |
| 3369 | direct-abstract-declarator[opt] ( parameter-forward-declarations |
| 3370 | parameter-type-list[opt] ) |
| 3371 | |
| 3372 | parameter-forward-declarations: |
| 3373 | parameter-list ; |
| 3374 | parameter-forward-declarations parameter-list ; |
| 3375 | |
| 3376 | The uses of attributes shown above are GNU extensions. |
| 3377 | |
| 3378 | Some forms of array declarator are not included in C99 in the |
| 3379 | syntax for abstract declarators; these are disallowed elsewhere. |
| 3380 | This may be a defect (DR#289). |
| 3381 | |
| 3382 | This function also accepts an omitted abstract declarator as being |
| 3383 | an abstract declarator, although not part of the formal syntax. */ |
| 3384 | |
| 3385 | struct c_declarator * |
| 3386 | c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind, |
| 3387 | bool *seen_id) |
| 3388 | { |
| 3389 | /* Parse any initial pointer part. */ |
| 3390 | if (c_parser_next_token_is (parser, CPP_MULT)) |
| 3391 | { |
| 3392 | struct c_declspecs *quals_attrs = build_null_declspecs (); |
| 3393 | struct c_declarator *inner; |
| 3394 | c_parser_consume_token (parser); |
| 3395 | c_parser_declspecs (parser, quals_attrs, false, false, true, |
| 3396 | false, false, cla_prefer_id); |
| 3397 | inner = c_parser_declarator (parser, type_seen_p, kind, seen_id); |
| 3398 | if (inner == NULL) |
| 3399 | return NULL; |
| 3400 | else |
| 3401 | return make_pointer_declarator (quals_attrs, inner); |
| 3402 | } |
| 3403 | /* Now we have a direct declarator, direct abstract declarator or |
| 3404 | nothing (which counts as a direct abstract declarator here). */ |
| 3405 | return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id); |
| 3406 | } |
| 3407 | |
| 3408 | /* Parse a direct declarator or direct abstract declarator; arguments |
| 3409 | as c_parser_declarator. */ |
| 3410 | |
| 3411 | static struct c_declarator * |
| 3412 | c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind, |
| 3413 | bool *seen_id) |
| 3414 | { |
| 3415 | /* The direct declarator must start with an identifier (possibly |
| 3416 | omitted) or a parenthesized declarator (possibly abstract). In |
| 3417 | an ordinary declarator, initial parentheses must start a |
| 3418 | parenthesized declarator. In an abstract declarator or parameter |
| 3419 | declarator, they could start a parenthesized declarator or a |
| 3420 | parameter list. To tell which, the open parenthesis and any |
| 3421 | following attributes must be read. If a declaration specifier |
| 3422 | follows, then it is a parameter list; if the specifier is a |
| 3423 | typedef name, there might be an ambiguity about redeclaring it, |
| 3424 | which is resolved in the direction of treating it as a typedef |
| 3425 | name. If a close parenthesis follows, it is also an empty |
| 3426 | parameter list, as the syntax does not permit empty abstract |
| 3427 | declarators. Otherwise, it is a parenthesized declarator (in |
| 3428 | which case the analysis may be repeated inside it, recursively). |
| 3429 | |
| 3430 | ??? There is an ambiguity in a parameter declaration "int |
| 3431 | (__attribute__((foo)) x)", where x is not a typedef name: it |
| 3432 | could be an abstract declarator for a function, or declare x with |
| 3433 | parentheses. The proper resolution of this ambiguity needs |
| 3434 | documenting. At present we follow an accident of the old |
| 3435 | parser's implementation, whereby the first parameter must have |
| 3436 | some declaration specifiers other than just attributes. Thus as |
| 3437 | a parameter declaration it is treated as a parenthesized |
| 3438 | parameter named x, and as an abstract declarator it is |
| 3439 | rejected. |
| 3440 | |
| 3441 | ??? Also following the old parser, attributes inside an empty |
| 3442 | parameter list are ignored, making it a list not yielding a |
| 3443 | prototype, rather than giving an error or making it have one |
| 3444 | parameter with implicit type int. |
| 3445 | |
| 3446 | ??? Also following the old parser, typedef names may be |
| 3447 | redeclared in declarators, but not Objective-C class names. */ |
| 3448 | |
| 3449 | if (kind != C_DTR_ABSTRACT |
| 3450 | && c_parser_next_token_is (parser, CPP_NAME) |
| 3451 | && ((type_seen_p |
| 3452 | && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME |
| 3453 | || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)) |
| 3454 | || c_parser_peek_token (parser)->id_kind == C_ID_ID)) |
| 3455 | { |
| 3456 | struct c_declarator *inner |
| 3457 | = build_id_declarator (c_parser_peek_token (parser)->value); |
| 3458 | *seen_id = true; |
| 3459 | inner->id_loc = c_parser_peek_token (parser)->location; |
| 3460 | c_parser_consume_token (parser); |
| 3461 | return c_parser_direct_declarator_inner (parser, *seen_id, inner); |
| 3462 | } |
| 3463 | |
| 3464 | if (kind != C_DTR_NORMAL |
| 3465 | && c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) |
| 3466 | { |
| 3467 | struct c_declarator *inner = build_id_declarator (NULL_TREE); |
| 3468 | inner->id_loc = c_parser_peek_token (parser)->location; |
| 3469 | return c_parser_direct_declarator_inner (parser, *seen_id, inner); |
| 3470 | } |
| 3471 | |
| 3472 | /* Either we are at the end of an abstract declarator, or we have |
| 3473 | parentheses. */ |
| 3474 | |
| 3475 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 3476 | { |
| 3477 | tree attrs; |
| 3478 | struct c_declarator *inner; |
| 3479 | c_parser_consume_token (parser); |
| 3480 | attrs = c_parser_attributes (parser); |
| 3481 | if (kind != C_DTR_NORMAL |
| 3482 | && (c_parser_next_token_starts_declspecs (parser) |
| 3483 | || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))) |
| 3484 | { |
| 3485 | struct c_arg_info *args |
| 3486 | = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL, |
| 3487 | attrs); |
| 3488 | if (args == NULL) |
| 3489 | return NULL; |
| 3490 | else |
| 3491 | { |
| 3492 | inner |
| 3493 | = build_function_declarator (args, |
| 3494 | build_id_declarator (NULL_TREE)); |
| 3495 | return c_parser_direct_declarator_inner (parser, *seen_id, |
| 3496 | inner); |
| 3497 | } |
| 3498 | } |
| 3499 | /* A parenthesized declarator. */ |
| 3500 | inner = c_parser_declarator (parser, type_seen_p, kind, seen_id); |
| 3501 | if (inner != NULL && attrs != NULL) |
| 3502 | inner = build_attrs_declarator (attrs, inner); |
| 3503 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 3504 | { |
| 3505 | c_parser_consume_token (parser); |
| 3506 | if (inner == NULL) |
| 3507 | return NULL; |
| 3508 | else |
| 3509 | return c_parser_direct_declarator_inner (parser, *seen_id, inner); |
| 3510 | } |
| 3511 | else |
| 3512 | { |
| 3513 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 3514 | "expected %<)%>" ); |
| 3515 | return NULL; |
| 3516 | } |
| 3517 | } |
| 3518 | else |
| 3519 | { |
| 3520 | if (kind == C_DTR_NORMAL) |
| 3521 | { |
| 3522 | c_parser_error (parser, "expected identifier or %<(%>" ); |
| 3523 | return NULL; |
| 3524 | } |
| 3525 | else |
| 3526 | return build_id_declarator (NULL_TREE); |
| 3527 | } |
| 3528 | } |
| 3529 | |
| 3530 | /* Parse part of a direct declarator or direct abstract declarator, |
| 3531 | given that some (in INNER) has already been parsed; ID_PRESENT is |
| 3532 | true if an identifier is present, false for an abstract |
| 3533 | declarator. */ |
| 3534 | |
| 3535 | static struct c_declarator * |
| 3536 | c_parser_direct_declarator_inner (c_parser *parser, bool id_present, |
| 3537 | struct c_declarator *inner) |
| 3538 | { |
| 3539 | /* Parse a sequence of array declarators and parameter lists. */ |
| 3540 | if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) |
| 3541 | { |
| 3542 | location_t brace_loc = c_parser_peek_token (parser)->location; |
| 3543 | struct c_declarator *declarator; |
| 3544 | struct c_declspecs *quals_attrs = build_null_declspecs (); |
| 3545 | bool static_seen; |
| 3546 | bool star_seen; |
| 3547 | struct c_expr dimen; |
| 3548 | dimen.value = NULL_TREE; |
| 3549 | dimen.original_code = ERROR_MARK; |
| 3550 | dimen.original_type = NULL_TREE; |
| 3551 | c_parser_consume_token (parser); |
| 3552 | c_parser_declspecs (parser, quals_attrs, false, false, true, |
| 3553 | false, false, cla_prefer_id); |
| 3554 | static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC); |
| 3555 | if (static_seen) |
| 3556 | c_parser_consume_token (parser); |
| 3557 | if (static_seen && !quals_attrs->declspecs_seen_p) |
| 3558 | c_parser_declspecs (parser, quals_attrs, false, false, true, |
| 3559 | false, false, cla_prefer_id); |
| 3560 | if (!quals_attrs->declspecs_seen_p) |
| 3561 | quals_attrs = NULL; |
| 3562 | /* If "static" is present, there must be an array dimension. |
| 3563 | Otherwise, there may be a dimension, "*", or no |
| 3564 | dimension. */ |
| 3565 | if (static_seen) |
| 3566 | { |
| 3567 | star_seen = false; |
| 3568 | dimen = c_parser_expr_no_commas (parser, NULL); |
| 3569 | } |
| 3570 | else |
| 3571 | { |
| 3572 | if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) |
| 3573 | { |
| 3574 | dimen.value = NULL_TREE; |
| 3575 | star_seen = false; |
| 3576 | } |
| 3577 | else if (flag_cilkplus |
| 3578 | && c_parser_next_token_is (parser, CPP_COLON)) |
| 3579 | { |
| 3580 | dimen.value = error_mark_node; |
| 3581 | star_seen = false; |
| 3582 | error_at (c_parser_peek_token (parser)->location, |
| 3583 | "array notations cannot be used in declaration" ); |
| 3584 | c_parser_consume_token (parser); |
| 3585 | } |
| 3586 | else if (c_parser_next_token_is (parser, CPP_MULT)) |
| 3587 | { |
| 3588 | if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE) |
| 3589 | { |
| 3590 | dimen.value = NULL_TREE; |
| 3591 | star_seen = true; |
| 3592 | c_parser_consume_token (parser); |
| 3593 | } |
| 3594 | else |
| 3595 | { |
| 3596 | star_seen = false; |
| 3597 | dimen = c_parser_expr_no_commas (parser, NULL); |
| 3598 | } |
| 3599 | } |
| 3600 | else |
| 3601 | { |
| 3602 | star_seen = false; |
| 3603 | dimen = c_parser_expr_no_commas (parser, NULL); |
| 3604 | } |
| 3605 | } |
| 3606 | if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) |
| 3607 | c_parser_consume_token (parser); |
| 3608 | else if (flag_cilkplus |
| 3609 | && c_parser_next_token_is (parser, CPP_COLON)) |
| 3610 | { |
| 3611 | error_at (c_parser_peek_token (parser)->location, |
| 3612 | "array notations cannot be used in declaration" ); |
| 3613 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); |
| 3614 | return NULL; |
| 3615 | } |
| 3616 | else |
| 3617 | { |
| 3618 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, |
| 3619 | "expected %<]%>" ); |
| 3620 | return NULL; |
| 3621 | } |
| 3622 | if (dimen.value) |
| 3623 | dimen = convert_lvalue_to_rvalue (brace_loc, dimen, true, true); |
| 3624 | declarator = build_array_declarator (brace_loc, dimen.value, quals_attrs, |
| 3625 | static_seen, star_seen); |
| 3626 | if (declarator == NULL) |
| 3627 | return NULL; |
| 3628 | inner = set_array_declarator_inner (declarator, inner); |
| 3629 | return c_parser_direct_declarator_inner (parser, id_present, inner); |
| 3630 | } |
| 3631 | else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 3632 | { |
| 3633 | tree attrs; |
| 3634 | struct c_arg_info *args; |
| 3635 | c_parser_consume_token (parser); |
| 3636 | attrs = c_parser_attributes (parser); |
| 3637 | args = c_parser_parms_declarator (parser, id_present, attrs); |
| 3638 | if (args == NULL) |
| 3639 | return NULL; |
| 3640 | else |
| 3641 | { |
| 3642 | inner = build_function_declarator (args, inner); |
| 3643 | return c_parser_direct_declarator_inner (parser, id_present, inner); |
| 3644 | } |
| 3645 | } |
| 3646 | return inner; |
| 3647 | } |
| 3648 | |
| 3649 | /* Parse a parameter list or identifier list, including the closing |
| 3650 | parenthesis but not the opening one. ATTRS are the attributes at |
| 3651 | the start of the list. ID_LIST_OK is true if an identifier list is |
| 3652 | acceptable; such a list must not have attributes at the start. */ |
| 3653 | |
| 3654 | static struct c_arg_info * |
| 3655 | c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs) |
| 3656 | { |
| 3657 | push_scope (); |
| 3658 | declare_parm_level (); |
| 3659 | /* If the list starts with an identifier, it is an identifier list. |
| 3660 | Otherwise, it is either a prototype list or an empty list. */ |
| 3661 | if (id_list_ok |
| 3662 | && !attrs |
| 3663 | && c_parser_next_token_is (parser, CPP_NAME) |
| 3664 | && c_parser_peek_token (parser)->id_kind == C_ID_ID |
| 3665 | |
| 3666 | /* Look ahead to detect typos in type names. */ |
| 3667 | && c_parser_peek_2nd_token (parser)->type != CPP_NAME |
| 3668 | && c_parser_peek_2nd_token (parser)->type != CPP_MULT |
| 3669 | && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN |
| 3670 | && c_parser_peek_2nd_token (parser)->type != CPP_OPEN_SQUARE |
| 3671 | && c_parser_peek_2nd_token (parser)->type != CPP_KEYWORD) |
| 3672 | { |
| 3673 | tree list = NULL_TREE, *nextp = &list; |
| 3674 | while (c_parser_next_token_is (parser, CPP_NAME) |
| 3675 | && c_parser_peek_token (parser)->id_kind == C_ID_ID) |
| 3676 | { |
| 3677 | *nextp = build_tree_list (NULL_TREE, |
| 3678 | c_parser_peek_token (parser)->value); |
| 3679 | nextp = & TREE_CHAIN (*nextp); |
| 3680 | c_parser_consume_token (parser); |
| 3681 | if (c_parser_next_token_is_not (parser, CPP_COMMA)) |
| 3682 | break; |
| 3683 | c_parser_consume_token (parser); |
| 3684 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 3685 | { |
| 3686 | c_parser_error (parser, "expected identifier" ); |
| 3687 | break; |
| 3688 | } |
| 3689 | } |
| 3690 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 3691 | { |
| 3692 | struct c_arg_info *ret = build_arg_info (); |
| 3693 | ret->types = list; |
| 3694 | c_parser_consume_token (parser); |
| 3695 | pop_scope (); |
| 3696 | return ret; |
| 3697 | } |
| 3698 | else |
| 3699 | { |
| 3700 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 3701 | "expected %<)%>" ); |
| 3702 | pop_scope (); |
| 3703 | return NULL; |
| 3704 | } |
| 3705 | } |
| 3706 | else |
| 3707 | { |
| 3708 | struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs, |
| 3709 | NULL); |
| 3710 | pop_scope (); |
| 3711 | return ret; |
| 3712 | } |
| 3713 | } |
| 3714 | |
| 3715 | /* Parse a parameter list (possibly empty), including the closing |
| 3716 | parenthesis but not the opening one. ATTRS are the attributes at |
| 3717 | the start of the list. EXPR is NULL or an expression that needs to |
| 3718 | be evaluated for the side effects of array size expressions in the |
| 3719 | parameters. */ |
| 3720 | |
| 3721 | static struct c_arg_info * |
| 3722 | c_parser_parms_list_declarator (c_parser *parser, tree attrs, tree expr) |
| 3723 | { |
| 3724 | bool bad_parm = false; |
| 3725 | |
| 3726 | /* ??? Following the old parser, forward parameter declarations may |
| 3727 | use abstract declarators, and if no real parameter declarations |
| 3728 | follow the forward declarations then this is not diagnosed. Also |
| 3729 | note as above that attributes are ignored as the only contents of |
| 3730 | the parentheses, or as the only contents after forward |
| 3731 | declarations. */ |
| 3732 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 3733 | { |
| 3734 | struct c_arg_info *ret = build_arg_info (); |
| 3735 | c_parser_consume_token (parser); |
| 3736 | return ret; |
| 3737 | } |
| 3738 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) |
| 3739 | { |
| 3740 | struct c_arg_info *ret = build_arg_info (); |
| 3741 | |
| 3742 | if (flag_allow_parameterless_variadic_functions) |
| 3743 | { |
| 3744 | /* F (...) is allowed. */ |
| 3745 | ret->types = NULL_TREE; |
| 3746 | } |
| 3747 | else |
| 3748 | { |
| 3749 | /* Suppress -Wold-style-definition for this case. */ |
| 3750 | ret->types = error_mark_node; |
| 3751 | error_at (c_parser_peek_token (parser)->location, |
| 3752 | "ISO C requires a named argument before %<...%>" ); |
| 3753 | } |
| 3754 | c_parser_consume_token (parser); |
| 3755 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 3756 | { |
| 3757 | c_parser_consume_token (parser); |
| 3758 | return ret; |
| 3759 | } |
| 3760 | else |
| 3761 | { |
| 3762 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 3763 | "expected %<)%>" ); |
| 3764 | return NULL; |
| 3765 | } |
| 3766 | } |
| 3767 | /* Nonempty list of parameters, either terminated with semicolon |
| 3768 | (forward declarations; recurse) or with close parenthesis (normal |
| 3769 | function) or with ", ... )" (variadic function). */ |
| 3770 | while (true) |
| 3771 | { |
| 3772 | /* Parse a parameter. */ |
| 3773 | struct c_parm *parm = c_parser_parameter_declaration (parser, attrs); |
| 3774 | attrs = NULL_TREE; |
| 3775 | if (parm == NULL) |
| 3776 | bad_parm = true; |
| 3777 | else |
| 3778 | push_parm_decl (parm, &expr); |
| 3779 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 3780 | { |
| 3781 | tree new_attrs; |
| 3782 | c_parser_consume_token (parser); |
| 3783 | mark_forward_parm_decls (); |
| 3784 | new_attrs = c_parser_attributes (parser); |
| 3785 | return c_parser_parms_list_declarator (parser, new_attrs, expr); |
| 3786 | } |
| 3787 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 3788 | { |
| 3789 | c_parser_consume_token (parser); |
| 3790 | if (bad_parm) |
| 3791 | return NULL; |
| 3792 | else |
| 3793 | return get_parm_info (false, expr); |
| 3794 | } |
| 3795 | if (!c_parser_require (parser, CPP_COMMA, |
| 3796 | "expected %<;%>, %<,%> or %<)%>" )) |
| 3797 | { |
| 3798 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 3799 | return NULL; |
| 3800 | } |
| 3801 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) |
| 3802 | { |
| 3803 | c_parser_consume_token (parser); |
| 3804 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 3805 | { |
| 3806 | c_parser_consume_token (parser); |
| 3807 | if (bad_parm) |
| 3808 | return NULL; |
| 3809 | else |
| 3810 | return get_parm_info (true, expr); |
| 3811 | } |
| 3812 | else |
| 3813 | { |
| 3814 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 3815 | "expected %<)%>" ); |
| 3816 | return NULL; |
| 3817 | } |
| 3818 | } |
| 3819 | } |
| 3820 | } |
| 3821 | |
| 3822 | /* Parse a parameter declaration. ATTRS are the attributes at the |
| 3823 | start of the declaration if it is the first parameter. */ |
| 3824 | |
| 3825 | static struct c_parm * |
| 3826 | c_parser_parameter_declaration (c_parser *parser, tree attrs) |
| 3827 | { |
| 3828 | struct c_declspecs *specs; |
| 3829 | struct c_declarator *declarator; |
| 3830 | tree prefix_attrs; |
| 3831 | tree postfix_attrs = NULL_TREE; |
| 3832 | bool dummy = false; |
| 3833 | |
| 3834 | /* Accept #pragmas between parameter declarations. */ |
| 3835 | while (c_parser_next_token_is (parser, CPP_PRAGMA)) |
| 3836 | c_parser_pragma (parser, pragma_param, NULL); |
| 3837 | |
| 3838 | if (!c_parser_next_token_starts_declspecs (parser)) |
| 3839 | { |
| 3840 | c_token *token = c_parser_peek_token (parser); |
| 3841 | if (parser->error) |
| 3842 | return NULL; |
| 3843 | c_parser_set_source_position_from_token (token); |
| 3844 | if (c_parser_next_tokens_start_typename (parser, cla_prefer_type)) |
| 3845 | { |
| 3846 | const char *hint = lookup_name_fuzzy (token->value, |
| 3847 | FUZZY_LOOKUP_TYPENAME); |
| 3848 | if (hint) |
| 3849 | { |
| 3850 | gcc_rich_location richloc (token->location); |
| 3851 | richloc.add_fixit_replace (hint); |
| 3852 | error_at_rich_loc (&richloc, |
| 3853 | "unknown type name %qE; did you mean %qs?" , |
| 3854 | token->value, hint); |
| 3855 | } |
| 3856 | else |
| 3857 | error_at (token->location, "unknown type name %qE" , token->value); |
| 3858 | parser->error = true; |
| 3859 | } |
| 3860 | /* ??? In some Objective-C cases '...' isn't applicable so there |
| 3861 | should be a different message. */ |
| 3862 | else |
| 3863 | c_parser_error (parser, |
| 3864 | "expected declaration specifiers or %<...%>" ); |
| 3865 | c_parser_skip_to_end_of_parameter (parser); |
| 3866 | return NULL; |
| 3867 | } |
| 3868 | specs = build_null_declspecs (); |
| 3869 | if (attrs) |
| 3870 | { |
| 3871 | declspecs_add_attrs (input_location, specs, attrs); |
| 3872 | attrs = NULL_TREE; |
| 3873 | } |
| 3874 | c_parser_declspecs (parser, specs, true, true, true, true, false, |
| 3875 | cla_nonabstract_decl); |
| 3876 | finish_declspecs (specs); |
| 3877 | pending_xref_error (); |
| 3878 | prefix_attrs = specs->attrs; |
| 3879 | specs->attrs = NULL_TREE; |
| 3880 | declarator = c_parser_declarator (parser, |
| 3881 | specs->typespec_kind != ctsk_none, |
| 3882 | C_DTR_PARM, &dummy); |
| 3883 | if (declarator == NULL) |
| 3884 | { |
| 3885 | c_parser_skip_until_found (parser, CPP_COMMA, NULL); |
| 3886 | return NULL; |
| 3887 | } |
| 3888 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 3889 | postfix_attrs = c_parser_attributes (parser); |
| 3890 | return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs), |
| 3891 | declarator); |
| 3892 | } |
| 3893 | |
| 3894 | /* Parse a string literal in an asm expression. It should not be |
| 3895 | translated, and wide string literals are an error although |
| 3896 | permitted by the syntax. This is a GNU extension. |
| 3897 | |
| 3898 | asm-string-literal: |
| 3899 | string-literal |
| 3900 | |
| 3901 | ??? At present, following the old parser, the caller needs to have |
| 3902 | set lex_untranslated_string to 1. It would be better to follow the |
| 3903 | C++ parser rather than using this kludge. */ |
| 3904 | |
| 3905 | static tree |
| 3906 | c_parser_asm_string_literal (c_parser *parser) |
| 3907 | { |
| 3908 | tree str; |
| 3909 | int save_flag = warn_overlength_strings; |
| 3910 | warn_overlength_strings = 0; |
| 3911 | if (c_parser_next_token_is (parser, CPP_STRING)) |
| 3912 | { |
| 3913 | str = c_parser_peek_token (parser)->value; |
| 3914 | c_parser_consume_token (parser); |
| 3915 | } |
| 3916 | else if (c_parser_next_token_is (parser, CPP_WSTRING)) |
| 3917 | { |
| 3918 | error_at (c_parser_peek_token (parser)->location, |
| 3919 | "wide string literal in %<asm%>" ); |
| 3920 | str = build_string (1, "" ); |
| 3921 | c_parser_consume_token (parser); |
| 3922 | } |
| 3923 | else |
| 3924 | { |
| 3925 | c_parser_error (parser, "expected string literal" ); |
| 3926 | str = NULL_TREE; |
| 3927 | } |
| 3928 | warn_overlength_strings = save_flag; |
| 3929 | return str; |
| 3930 | } |
| 3931 | |
| 3932 | /* Parse a simple asm expression. This is used in restricted |
| 3933 | contexts, where a full expression with inputs and outputs does not |
| 3934 | make sense. This is a GNU extension. |
| 3935 | |
| 3936 | simple-asm-expr: |
| 3937 | asm ( asm-string-literal ) |
| 3938 | */ |
| 3939 | |
| 3940 | static tree |
| 3941 | c_parser_simple_asm_expr (c_parser *parser) |
| 3942 | { |
| 3943 | tree str; |
| 3944 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM)); |
| 3945 | /* ??? Follow the C++ parser rather than using the |
| 3946 | lex_untranslated_string kludge. */ |
| 3947 | parser->lex_untranslated_string = true; |
| 3948 | c_parser_consume_token (parser); |
| 3949 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 3950 | { |
| 3951 | parser->lex_untranslated_string = false; |
| 3952 | return NULL_TREE; |
| 3953 | } |
| 3954 | str = c_parser_asm_string_literal (parser); |
| 3955 | parser->lex_untranslated_string = false; |
| 3956 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>" )) |
| 3957 | { |
| 3958 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 3959 | return NULL_TREE; |
| 3960 | } |
| 3961 | return str; |
| 3962 | } |
| 3963 | |
| 3964 | static tree |
| 3965 | c_parser_attribute_any_word (c_parser *parser) |
| 3966 | { |
| 3967 | tree attr_name = NULL_TREE; |
| 3968 | |
| 3969 | if (c_parser_next_token_is (parser, CPP_KEYWORD)) |
| 3970 | { |
| 3971 | /* ??? See comment above about what keywords are accepted here. */ |
| 3972 | bool ok; |
| 3973 | switch (c_parser_peek_token (parser)->keyword) |
| 3974 | { |
| 3975 | case RID_STATIC: |
| 3976 | case RID_UNSIGNED: |
| 3977 | case RID_LONG: |
| 3978 | case RID_CONST: |
| 3979 | case RID_EXTERN: |
| 3980 | case RID_REGISTER: |
| 3981 | case RID_TYPEDEF: |
| 3982 | case RID_SHORT: |
| 3983 | case RID_INLINE: |
| 3984 | case RID_NORETURN: |
| 3985 | case RID_VOLATILE: |
| 3986 | case RID_SIGNED: |
| 3987 | case RID_AUTO: |
| 3988 | case RID_RESTRICT: |
| 3989 | case RID_COMPLEX: |
| 3990 | case RID_THREAD: |
| 3991 | case RID_INT: |
| 3992 | case RID_CHAR: |
| 3993 | case RID_FLOAT: |
| 3994 | case RID_DOUBLE: |
| 3995 | case RID_VOID: |
| 3996 | case RID_DFLOAT32: |
| 3997 | case RID_DFLOAT64: |
| 3998 | case RID_DFLOAT128: |
| 3999 | CASE_RID_FLOATN_NX: |
| 4000 | case RID_BOOL: |
| 4001 | case RID_FRACT: |
| 4002 | case RID_ACCUM: |
| 4003 | case RID_SAT: |
| 4004 | case RID_TRANSACTION_ATOMIC: |
| 4005 | case RID_TRANSACTION_CANCEL: |
| 4006 | case RID_ATOMIC: |
| 4007 | case RID_AUTO_TYPE: |
| 4008 | case RID_INT_N_0: |
| 4009 | case RID_INT_N_1: |
| 4010 | case RID_INT_N_2: |
| 4011 | case RID_INT_N_3: |
| 4012 | ok = true; |
| 4013 | break; |
| 4014 | default: |
| 4015 | ok = false; |
| 4016 | break; |
| 4017 | } |
| 4018 | if (!ok) |
| 4019 | return NULL_TREE; |
| 4020 | |
| 4021 | /* Accept __attribute__((__const)) as __attribute__((const)) etc. */ |
| 4022 | attr_name = ridpointers[(int) c_parser_peek_token (parser)->keyword]; |
| 4023 | } |
| 4024 | else if (c_parser_next_token_is (parser, CPP_NAME)) |
| 4025 | attr_name = c_parser_peek_token (parser)->value; |
| 4026 | |
| 4027 | return attr_name; |
| 4028 | } |
| 4029 | |
| 4030 | #define CILK_SIMD_FN_CLAUSE_MASK \ |
| 4031 | ((OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_VECTORLENGTH) \ |
| 4032 | | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_LINEAR) \ |
| 4033 | | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_UNIFORM) \ |
| 4034 | | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_MASK) \ |
| 4035 | | (OMP_CLAUSE_MASK_1 << PRAGMA_CILK_CLAUSE_NOMASK)) |
| 4036 | |
| 4037 | /* Parses the vector attribute of SIMD enabled functions in Cilk Plus. |
| 4038 | VEC_TOKEN is the "vector" token that is replaced with "simd" and |
| 4039 | pushed into the token list. |
| 4040 | Syntax: |
| 4041 | vector |
| 4042 | vector (<vector attributes>). */ |
| 4043 | |
| 4044 | static void |
| 4045 | c_parser_cilk_simd_fn_vector_attrs (c_parser *parser, c_token vec_token) |
| 4046 | { |
| 4047 | gcc_assert (is_cilkplus_vector_p (vec_token.value)); |
| 4048 | |
| 4049 | int paren_scope = 0; |
| 4050 | vec_safe_push (parser->cilk_simd_fn_tokens, vec_token); |
| 4051 | /* Consume the "vector" token. */ |
| 4052 | c_parser_consume_token (parser); |
| 4053 | |
| 4054 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 4055 | { |
| 4056 | c_parser_consume_token (parser); |
| 4057 | paren_scope++; |
| 4058 | } |
| 4059 | while (paren_scope > 0) |
| 4060 | { |
| 4061 | c_token *token = c_parser_peek_token (parser); |
| 4062 | if (token->type == CPP_OPEN_PAREN) |
| 4063 | paren_scope++; |
| 4064 | else if (token->type == CPP_CLOSE_PAREN) |
| 4065 | paren_scope--; |
| 4066 | /* Do not push the last ')' since we are not pushing the '('. */ |
| 4067 | if (!(token->type == CPP_CLOSE_PAREN && paren_scope == 0)) |
| 4068 | vec_safe_push (parser->cilk_simd_fn_tokens, *token); |
| 4069 | c_parser_consume_token (parser); |
| 4070 | } |
| 4071 | |
| 4072 | /* Since we are converting an attribute to a pragma, we need to end the |
| 4073 | attribute with PRAGMA_EOL. */ |
| 4074 | c_token eol_token; |
| 4075 | memset (&eol_token, 0, sizeof (eol_token)); |
| 4076 | eol_token.type = CPP_PRAGMA_EOL; |
| 4077 | vec_safe_push (parser->cilk_simd_fn_tokens, eol_token); |
| 4078 | } |
| 4079 | |
| 4080 | /* Add 2 CPP_EOF at the end of PARSER->ELEM_FN_TOKENS vector. */ |
| 4081 | |
| 4082 | static void |
| 4083 | c_finish_cilk_simd_fn_tokens (c_parser *parser) |
| 4084 | { |
| 4085 | c_token last_token = parser->cilk_simd_fn_tokens->last (); |
| 4086 | |
| 4087 | /* c_parser_attributes is called in several places, so if these EOF |
| 4088 | tokens are already inserted, then don't do them again. */ |
| 4089 | if (last_token.type == CPP_EOF) |
| 4090 | return; |
| 4091 | |
| 4092 | /* Two CPP_EOF token are added as a safety net since the normal C |
| 4093 | front-end has two token look-ahead. */ |
| 4094 | c_token eof_token; |
| 4095 | eof_token.type = CPP_EOF; |
| 4096 | vec_safe_push (parser->cilk_simd_fn_tokens, eof_token); |
| 4097 | vec_safe_push (parser->cilk_simd_fn_tokens, eof_token); |
| 4098 | } |
| 4099 | |
| 4100 | /* Parse (possibly empty) attributes. This is a GNU extension. |
| 4101 | |
| 4102 | attributes: |
| 4103 | empty |
| 4104 | attributes attribute |
| 4105 | |
| 4106 | attribute: |
| 4107 | __attribute__ ( ( attribute-list ) ) |
| 4108 | |
| 4109 | attribute-list: |
| 4110 | attrib |
| 4111 | attribute_list , attrib |
| 4112 | |
| 4113 | attrib: |
| 4114 | empty |
| 4115 | any-word |
| 4116 | any-word ( identifier ) |
| 4117 | any-word ( identifier , nonempty-expr-list ) |
| 4118 | any-word ( expr-list ) |
| 4119 | |
| 4120 | where the "identifier" must not be declared as a type, and |
| 4121 | "any-word" may be any identifier (including one declared as a |
| 4122 | type), a reserved word storage class specifier, type specifier or |
| 4123 | type qualifier. ??? This still leaves out most reserved keywords |
| 4124 | (following the old parser), shouldn't we include them, and why not |
| 4125 | allow identifiers declared as types to start the arguments? */ |
| 4126 | |
| 4127 | static tree |
| 4128 | c_parser_attributes (c_parser *parser) |
| 4129 | { |
| 4130 | tree attrs = NULL_TREE; |
| 4131 | while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 4132 | { |
| 4133 | /* ??? Follow the C++ parser rather than using the |
| 4134 | lex_untranslated_string kludge. */ |
| 4135 | parser->lex_untranslated_string = true; |
| 4136 | /* Consume the `__attribute__' keyword. */ |
| 4137 | c_parser_consume_token (parser); |
| 4138 | /* Look for the two `(' tokens. */ |
| 4139 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 4140 | { |
| 4141 | parser->lex_untranslated_string = false; |
| 4142 | return attrs; |
| 4143 | } |
| 4144 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 4145 | { |
| 4146 | parser->lex_untranslated_string = false; |
| 4147 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 4148 | return attrs; |
| 4149 | } |
| 4150 | /* Parse the attribute list. */ |
| 4151 | while (c_parser_next_token_is (parser, CPP_COMMA) |
| 4152 | || c_parser_next_token_is (parser, CPP_NAME) |
| 4153 | || c_parser_next_token_is (parser, CPP_KEYWORD)) |
| 4154 | { |
| 4155 | tree attr, attr_name, attr_args; |
| 4156 | vec<tree, va_gc> *expr_list; |
| 4157 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 4158 | { |
| 4159 | c_parser_consume_token (parser); |
| 4160 | continue; |
| 4161 | } |
| 4162 | |
| 4163 | attr_name = c_parser_attribute_any_word (parser); |
| 4164 | if (attr_name == NULL) |
| 4165 | break; |
| 4166 | if (is_cilkplus_vector_p (attr_name)) |
| 4167 | { |
| 4168 | c_token *v_token = c_parser_peek_token (parser); |
| 4169 | c_parser_cilk_simd_fn_vector_attrs (parser, *v_token); |
| 4170 | /* If the next token isn't a comma, we're done. */ |
| 4171 | if (!c_parser_next_token_is (parser, CPP_COMMA)) |
| 4172 | break; |
| 4173 | continue; |
| 4174 | } |
| 4175 | c_parser_consume_token (parser); |
| 4176 | if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN)) |
| 4177 | { |
| 4178 | attr = build_tree_list (attr_name, NULL_TREE); |
| 4179 | /* Add this attribute to the list. */ |
| 4180 | attrs = chainon (attrs, attr); |
| 4181 | /* If the next token isn't a comma, we're done. */ |
| 4182 | if (!c_parser_next_token_is (parser, CPP_COMMA)) |
| 4183 | break; |
| 4184 | continue; |
| 4185 | } |
| 4186 | c_parser_consume_token (parser); |
| 4187 | /* Parse the attribute contents. If they start with an |
| 4188 | identifier which is followed by a comma or close |
| 4189 | parenthesis, then the arguments start with that |
| 4190 | identifier; otherwise they are an expression list. |
| 4191 | In objective-c the identifier may be a classname. */ |
| 4192 | if (c_parser_next_token_is (parser, CPP_NAME) |
| 4193 | && (c_parser_peek_token (parser)->id_kind == C_ID_ID |
| 4194 | || (c_dialect_objc () |
| 4195 | && c_parser_peek_token (parser)->id_kind |
| 4196 | == C_ID_CLASSNAME)) |
| 4197 | && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA) |
| 4198 | || (c_parser_peek_2nd_token (parser)->type |
| 4199 | == CPP_CLOSE_PAREN)) |
| 4200 | && (attribute_takes_identifier_p (attr_name) |
| 4201 | || (c_dialect_objc () |
| 4202 | && c_parser_peek_token (parser)->id_kind |
| 4203 | == C_ID_CLASSNAME))) |
| 4204 | { |
| 4205 | tree arg1 = c_parser_peek_token (parser)->value; |
| 4206 | c_parser_consume_token (parser); |
| 4207 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 4208 | attr_args = build_tree_list (NULL_TREE, arg1); |
| 4209 | else |
| 4210 | { |
| 4211 | tree tree_list; |
| 4212 | c_parser_consume_token (parser); |
| 4213 | expr_list = c_parser_expr_list (parser, false, true, |
| 4214 | NULL, NULL, NULL, NULL); |
| 4215 | tree_list = build_tree_list_vec (expr_list); |
| 4216 | attr_args = tree_cons (NULL_TREE, arg1, tree_list); |
| 4217 | release_tree_vector (expr_list); |
| 4218 | } |
| 4219 | } |
| 4220 | else |
| 4221 | { |
| 4222 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 4223 | attr_args = NULL_TREE; |
| 4224 | else |
| 4225 | { |
| 4226 | expr_list = c_parser_expr_list (parser, false, true, |
| 4227 | NULL, NULL, NULL, NULL); |
| 4228 | attr_args = build_tree_list_vec (expr_list); |
| 4229 | release_tree_vector (expr_list); |
| 4230 | } |
| 4231 | } |
| 4232 | attr = build_tree_list (attr_name, attr_args); |
| 4233 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 4234 | c_parser_consume_token (parser); |
| 4235 | else |
| 4236 | { |
| 4237 | parser->lex_untranslated_string = false; |
| 4238 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 4239 | "expected %<)%>" ); |
| 4240 | return attrs; |
| 4241 | } |
| 4242 | /* Add this attribute to the list. */ |
| 4243 | attrs = chainon (attrs, attr); |
| 4244 | /* If the next token isn't a comma, we're done. */ |
| 4245 | if (!c_parser_next_token_is (parser, CPP_COMMA)) |
| 4246 | break; |
| 4247 | } |
| 4248 | /* Look for the two `)' tokens. */ |
| 4249 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 4250 | c_parser_consume_token (parser); |
| 4251 | else |
| 4252 | { |
| 4253 | parser->lex_untranslated_string = false; |
| 4254 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 4255 | "expected %<)%>" ); |
| 4256 | return attrs; |
| 4257 | } |
| 4258 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 4259 | c_parser_consume_token (parser); |
| 4260 | else |
| 4261 | { |
| 4262 | parser->lex_untranslated_string = false; |
| 4263 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 4264 | "expected %<)%>" ); |
| 4265 | return attrs; |
| 4266 | } |
| 4267 | parser->lex_untranslated_string = false; |
| 4268 | } |
| 4269 | |
| 4270 | if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) |
| 4271 | c_finish_cilk_simd_fn_tokens (parser); |
| 4272 | return attrs; |
| 4273 | } |
| 4274 | |
| 4275 | /* Parse a type name (C90 6.5.5, C99 6.7.6, C11 6.7.7). |
| 4276 | |
| 4277 | type-name: |
| 4278 | specifier-qualifier-list abstract-declarator[opt] |
| 4279 | */ |
| 4280 | |
| 4281 | struct c_type_name * |
| 4282 | c_parser_type_name (c_parser *parser) |
| 4283 | { |
| 4284 | struct c_declspecs *specs = build_null_declspecs (); |
| 4285 | struct c_declarator *declarator; |
| 4286 | struct c_type_name *ret; |
| 4287 | bool dummy = false; |
| 4288 | c_parser_declspecs (parser, specs, false, true, true, false, false, |
| 4289 | cla_prefer_type); |
| 4290 | if (!specs->declspecs_seen_p) |
| 4291 | { |
| 4292 | c_parser_error (parser, "expected specifier-qualifier-list" ); |
| 4293 | return NULL; |
| 4294 | } |
| 4295 | if (specs->type != error_mark_node) |
| 4296 | { |
| 4297 | pending_xref_error (); |
| 4298 | finish_declspecs (specs); |
| 4299 | } |
| 4300 | declarator = c_parser_declarator (parser, |
| 4301 | specs->typespec_kind != ctsk_none, |
| 4302 | C_DTR_ABSTRACT, &dummy); |
| 4303 | if (declarator == NULL) |
| 4304 | return NULL; |
| 4305 | ret = XOBNEW (&parser_obstack, struct c_type_name); |
| 4306 | ret->specs = specs; |
| 4307 | ret->declarator = declarator; |
| 4308 | return ret; |
| 4309 | } |
| 4310 | |
| 4311 | /* Parse an initializer (C90 6.5.7, C99 6.7.8, C11 6.7.9). |
| 4312 | |
| 4313 | initializer: |
| 4314 | assignment-expression |
| 4315 | { initializer-list } |
| 4316 | { initializer-list , } |
| 4317 | |
| 4318 | initializer-list: |
| 4319 | designation[opt] initializer |
| 4320 | initializer-list , designation[opt] initializer |
| 4321 | |
| 4322 | designation: |
| 4323 | designator-list = |
| 4324 | |
| 4325 | designator-list: |
| 4326 | designator |
| 4327 | designator-list designator |
| 4328 | |
| 4329 | designator: |
| 4330 | array-designator |
| 4331 | . identifier |
| 4332 | |
| 4333 | array-designator: |
| 4334 | [ constant-expression ] |
| 4335 | |
| 4336 | GNU extensions: |
| 4337 | |
| 4338 | initializer: |
| 4339 | { } |
| 4340 | |
| 4341 | designation: |
| 4342 | array-designator |
| 4343 | identifier : |
| 4344 | |
| 4345 | array-designator: |
| 4346 | [ constant-expression ... constant-expression ] |
| 4347 | |
| 4348 | Any expression without commas is accepted in the syntax for the |
| 4349 | constant-expressions, with non-constant expressions rejected later. |
| 4350 | |
| 4351 | This function is only used for top-level initializers; for nested |
| 4352 | ones, see c_parser_initval. */ |
| 4353 | |
| 4354 | static struct c_expr |
| 4355 | c_parser_initializer (c_parser *parser) |
| 4356 | { |
| 4357 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 4358 | return c_parser_braced_init (parser, NULL_TREE, false, NULL); |
| 4359 | else |
| 4360 | { |
| 4361 | struct c_expr ret; |
| 4362 | location_t loc = c_parser_peek_token (parser)->location; |
| 4363 | ret = c_parser_expr_no_commas (parser, NULL); |
| 4364 | if (TREE_CODE (ret.value) != STRING_CST |
| 4365 | && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR) |
| 4366 | ret = convert_lvalue_to_rvalue (loc, ret, true, true); |
| 4367 | return ret; |
| 4368 | } |
| 4369 | } |
| 4370 | |
| 4371 | /* The location of the last comma within the current initializer list, |
| 4372 | or UNKNOWN_LOCATION if not within one. */ |
| 4373 | |
| 4374 | location_t last_init_list_comma; |
| 4375 | |
| 4376 | /* Parse a braced initializer list. TYPE is the type specified for a |
| 4377 | compound literal, and NULL_TREE for other initializers and for |
| 4378 | nested braced lists. NESTED_P is true for nested braced lists, |
| 4379 | false for the list of a compound literal or the list that is the |
| 4380 | top-level initializer in a declaration. */ |
| 4381 | |
| 4382 | static struct c_expr |
| 4383 | c_parser_braced_init (c_parser *parser, tree type, bool nested_p, |
| 4384 | struct obstack *outer_obstack) |
| 4385 | { |
| 4386 | struct c_expr ret; |
| 4387 | struct obstack braced_init_obstack; |
| 4388 | location_t brace_loc = c_parser_peek_token (parser)->location; |
| 4389 | gcc_obstack_init (&braced_init_obstack); |
| 4390 | gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE)); |
| 4391 | c_parser_consume_token (parser); |
| 4392 | if (nested_p) |
| 4393 | { |
| 4394 | finish_implicit_inits (brace_loc, outer_obstack); |
| 4395 | push_init_level (brace_loc, 0, &braced_init_obstack); |
| 4396 | } |
| 4397 | else |
| 4398 | really_start_incremental_init (type); |
| 4399 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 4400 | { |
| 4401 | pedwarn (brace_loc, OPT_Wpedantic, "ISO C forbids empty initializer braces" ); |
| 4402 | } |
| 4403 | else |
| 4404 | { |
| 4405 | /* Parse a non-empty initializer list, possibly with a trailing |
| 4406 | comma. */ |
| 4407 | while (true) |
| 4408 | { |
| 4409 | c_parser_initelt (parser, &braced_init_obstack); |
| 4410 | if (parser->error) |
| 4411 | break; |
| 4412 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 4413 | { |
| 4414 | last_init_list_comma = c_parser_peek_token (parser)->location; |
| 4415 | c_parser_consume_token (parser); |
| 4416 | } |
| 4417 | else |
| 4418 | break; |
| 4419 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 4420 | break; |
| 4421 | } |
| 4422 | } |
| 4423 | c_token *next_tok = c_parser_peek_token (parser); |
| 4424 | if (next_tok->type != CPP_CLOSE_BRACE) |
| 4425 | { |
| 4426 | ret.value = error_mark_node; |
| 4427 | ret.original_code = ERROR_MARK; |
| 4428 | ret.original_type = NULL; |
| 4429 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>" ); |
| 4430 | pop_init_level (brace_loc, 0, &braced_init_obstack, last_init_list_comma); |
| 4431 | obstack_free (&braced_init_obstack, NULL); |
| 4432 | return ret; |
| 4433 | } |
| 4434 | location_t close_loc = next_tok->location; |
| 4435 | c_parser_consume_token (parser); |
| 4436 | ret = pop_init_level (brace_loc, 0, &braced_init_obstack, close_loc); |
| 4437 | obstack_free (&braced_init_obstack, NULL); |
| 4438 | set_c_expr_source_range (&ret, brace_loc, close_loc); |
| 4439 | return ret; |
| 4440 | } |
| 4441 | |
| 4442 | /* Parse a nested initializer, including designators. */ |
| 4443 | |
| 4444 | static void |
| 4445 | c_parser_initelt (c_parser *parser, struct obstack * braced_init_obstack) |
| 4446 | { |
| 4447 | /* Parse any designator or designator list. A single array |
| 4448 | designator may have the subsequent "=" omitted in GNU C, but a |
| 4449 | longer list or a structure member designator may not. */ |
| 4450 | if (c_parser_next_token_is (parser, CPP_NAME) |
| 4451 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 4452 | { |
| 4453 | /* Old-style structure member designator. */ |
| 4454 | set_init_label (c_parser_peek_token (parser)->location, |
| 4455 | c_parser_peek_token (parser)->value, |
| 4456 | c_parser_peek_token (parser)->location, |
| 4457 | braced_init_obstack); |
| 4458 | /* Use the colon as the error location. */ |
| 4459 | pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_Wpedantic, |
| 4460 | "obsolete use of designated initializer with %<:%>" ); |
| 4461 | c_parser_consume_token (parser); |
| 4462 | c_parser_consume_token (parser); |
| 4463 | } |
| 4464 | else |
| 4465 | { |
| 4466 | /* des_seen is 0 if there have been no designators, 1 if there |
| 4467 | has been a single array designator and 2 otherwise. */ |
| 4468 | int des_seen = 0; |
| 4469 | /* Location of a designator. */ |
| 4470 | location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
| 4471 | while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE) |
| 4472 | || c_parser_next_token_is (parser, CPP_DOT)) |
| 4473 | { |
| 4474 | int des_prev = des_seen; |
| 4475 | if (!des_seen) |
| 4476 | des_loc = c_parser_peek_token (parser)->location; |
| 4477 | if (des_seen < 2) |
| 4478 | des_seen++; |
| 4479 | if (c_parser_next_token_is (parser, CPP_DOT)) |
| 4480 | { |
| 4481 | des_seen = 2; |
| 4482 | c_parser_consume_token (parser); |
| 4483 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 4484 | { |
| 4485 | set_init_label (des_loc, c_parser_peek_token (parser)->value, |
| 4486 | c_parser_peek_token (parser)->location, |
| 4487 | braced_init_obstack); |
| 4488 | c_parser_consume_token (parser); |
| 4489 | } |
| 4490 | else |
| 4491 | { |
| 4492 | struct c_expr init; |
| 4493 | init.value = error_mark_node; |
| 4494 | init.original_code = ERROR_MARK; |
| 4495 | init.original_type = NULL; |
| 4496 | c_parser_error (parser, "expected identifier" ); |
| 4497 | c_parser_skip_until_found (parser, CPP_COMMA, NULL); |
| 4498 | process_init_element (input_location, init, false, |
| 4499 | braced_init_obstack); |
| 4500 | return; |
| 4501 | } |
| 4502 | } |
| 4503 | else |
| 4504 | { |
| 4505 | tree first, second; |
| 4506 | location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
| 4507 | location_t array_index_loc = UNKNOWN_LOCATION; |
| 4508 | /* ??? Following the old parser, [ objc-receiver |
| 4509 | objc-message-args ] is accepted as an initializer, |
| 4510 | being distinguished from a designator by what follows |
| 4511 | the first assignment expression inside the square |
| 4512 | brackets, but after a first array designator a |
| 4513 | subsequent square bracket is for Objective-C taken to |
| 4514 | start an expression, using the obsolete form of |
| 4515 | designated initializer without '=', rather than |
| 4516 | possibly being a second level of designation: in LALR |
| 4517 | terms, the '[' is shifted rather than reducing |
| 4518 | designator to designator-list. */ |
| 4519 | if (des_prev == 1 && c_dialect_objc ()) |
| 4520 | { |
| 4521 | des_seen = des_prev; |
| 4522 | break; |
| 4523 | } |
| 4524 | if (des_prev == 0 && c_dialect_objc ()) |
| 4525 | { |
| 4526 | /* This might be an array designator or an |
| 4527 | Objective-C message expression. If the former, |
| 4528 | continue parsing here; if the latter, parse the |
| 4529 | remainder of the initializer given the starting |
| 4530 | primary-expression. ??? It might make sense to |
| 4531 | distinguish when des_prev == 1 as well; see |
| 4532 | previous comment. */ |
| 4533 | tree rec, args; |
| 4534 | struct c_expr mexpr; |
| 4535 | c_parser_consume_token (parser); |
| 4536 | if (c_parser_peek_token (parser)->type == CPP_NAME |
| 4537 | && ((c_parser_peek_token (parser)->id_kind |
| 4538 | == C_ID_TYPENAME) |
| 4539 | || (c_parser_peek_token (parser)->id_kind |
| 4540 | == C_ID_CLASSNAME))) |
| 4541 | { |
| 4542 | /* Type name receiver. */ |
| 4543 | tree id = c_parser_peek_token (parser)->value; |
| 4544 | c_parser_consume_token (parser); |
| 4545 | rec = objc_get_class_reference (id); |
| 4546 | goto parse_message_args; |
| 4547 | } |
| 4548 | first = c_parser_expr_no_commas (parser, NULL).value; |
| 4549 | mark_exp_read (first); |
| 4550 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS) |
| 4551 | || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) |
| 4552 | goto array_desig_after_first; |
| 4553 | /* Expression receiver. So far only one part |
| 4554 | without commas has been parsed; there might be |
| 4555 | more of the expression. */ |
| 4556 | rec = first; |
| 4557 | while (c_parser_next_token_is (parser, CPP_COMMA)) |
| 4558 | { |
| 4559 | struct c_expr next; |
| 4560 | location_t comma_loc, exp_loc; |
| 4561 | comma_loc = c_parser_peek_token (parser)->location; |
| 4562 | c_parser_consume_token (parser); |
| 4563 | exp_loc = c_parser_peek_token (parser)->location; |
| 4564 | next = c_parser_expr_no_commas (parser, NULL); |
| 4565 | next = convert_lvalue_to_rvalue (exp_loc, next, |
| 4566 | true, true); |
| 4567 | rec = build_compound_expr (comma_loc, rec, next.value); |
| 4568 | } |
| 4569 | parse_message_args: |
| 4570 | /* Now parse the objc-message-args. */ |
| 4571 | args = c_parser_objc_message_args (parser); |
| 4572 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, |
| 4573 | "expected %<]%>" ); |
| 4574 | mexpr.value |
| 4575 | = objc_build_message_expr (rec, args); |
| 4576 | mexpr.original_code = ERROR_MARK; |
| 4577 | mexpr.original_type = NULL; |
| 4578 | /* Now parse and process the remainder of the |
| 4579 | initializer, starting with this message |
| 4580 | expression as a primary-expression. */ |
| 4581 | c_parser_initval (parser, &mexpr, braced_init_obstack); |
| 4582 | return; |
| 4583 | } |
| 4584 | c_parser_consume_token (parser); |
| 4585 | array_index_loc = c_parser_peek_token (parser)->location; |
| 4586 | first = c_parser_expr_no_commas (parser, NULL).value; |
| 4587 | mark_exp_read (first); |
| 4588 | array_desig_after_first: |
| 4589 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) |
| 4590 | { |
| 4591 | ellipsis_loc = c_parser_peek_token (parser)->location; |
| 4592 | c_parser_consume_token (parser); |
| 4593 | second = c_parser_expr_no_commas (parser, NULL).value; |
| 4594 | mark_exp_read (second); |
| 4595 | } |
| 4596 | else |
| 4597 | second = NULL_TREE; |
| 4598 | if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) |
| 4599 | { |
| 4600 | c_parser_consume_token (parser); |
| 4601 | set_init_index (array_index_loc, first, second, |
| 4602 | braced_init_obstack); |
| 4603 | if (second) |
| 4604 | pedwarn (ellipsis_loc, OPT_Wpedantic, |
| 4605 | "ISO C forbids specifying range of elements to initialize" ); |
| 4606 | } |
| 4607 | else |
| 4608 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, |
| 4609 | "expected %<]%>" ); |
| 4610 | } |
| 4611 | } |
| 4612 | if (des_seen >= 1) |
| 4613 | { |
| 4614 | if (c_parser_next_token_is (parser, CPP_EQ)) |
| 4615 | { |
| 4616 | pedwarn_c90 (des_loc, OPT_Wpedantic, |
| 4617 | "ISO C90 forbids specifying subobject " |
| 4618 | "to initialize" ); |
| 4619 | c_parser_consume_token (parser); |
| 4620 | } |
| 4621 | else |
| 4622 | { |
| 4623 | if (des_seen == 1) |
| 4624 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
| 4625 | "obsolete use of designated initializer without %<=%>" ); |
| 4626 | else |
| 4627 | { |
| 4628 | struct c_expr init; |
| 4629 | init.value = error_mark_node; |
| 4630 | init.original_code = ERROR_MARK; |
| 4631 | init.original_type = NULL; |
| 4632 | c_parser_error (parser, "expected %<=%>" ); |
| 4633 | c_parser_skip_until_found (parser, CPP_COMMA, NULL); |
| 4634 | process_init_element (input_location, init, false, |
| 4635 | braced_init_obstack); |
| 4636 | return; |
| 4637 | } |
| 4638 | } |
| 4639 | } |
| 4640 | } |
| 4641 | c_parser_initval (parser, NULL, braced_init_obstack); |
| 4642 | } |
| 4643 | |
| 4644 | /* Parse a nested initializer; as c_parser_initializer but parses |
| 4645 | initializers within braced lists, after any designators have been |
| 4646 | applied. If AFTER is not NULL then it is an Objective-C message |
| 4647 | expression which is the primary-expression starting the |
| 4648 | initializer. */ |
| 4649 | |
| 4650 | static void |
| 4651 | c_parser_initval (c_parser *parser, struct c_expr *after, |
| 4652 | struct obstack * braced_init_obstack) |
| 4653 | { |
| 4654 | struct c_expr init; |
| 4655 | gcc_assert (!after || c_dialect_objc ()); |
| 4656 | location_t loc = c_parser_peek_token (parser)->location; |
| 4657 | |
| 4658 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after) |
| 4659 | init = c_parser_braced_init (parser, NULL_TREE, true, |
| 4660 | braced_init_obstack); |
| 4661 | else |
| 4662 | { |
| 4663 | init = c_parser_expr_no_commas (parser, after); |
| 4664 | if (init.value != NULL_TREE |
| 4665 | && TREE_CODE (init.value) != STRING_CST |
| 4666 | && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR) |
| 4667 | init = convert_lvalue_to_rvalue (loc, init, true, true); |
| 4668 | } |
| 4669 | process_init_element (loc, init, false, braced_init_obstack); |
| 4670 | } |
| 4671 | |
| 4672 | /* Parse a compound statement (possibly a function body) (C90 6.6.2, |
| 4673 | C99 6.8.2, C11 6.8.2). |
| 4674 | |
| 4675 | compound-statement: |
| 4676 | { block-item-list[opt] } |
| 4677 | { label-declarations block-item-list } |
| 4678 | |
| 4679 | block-item-list: |
| 4680 | block-item |
| 4681 | block-item-list block-item |
| 4682 | |
| 4683 | block-item: |
| 4684 | nested-declaration |
| 4685 | statement |
| 4686 | |
| 4687 | nested-declaration: |
| 4688 | declaration |
| 4689 | |
| 4690 | GNU extensions: |
| 4691 | |
| 4692 | compound-statement: |
| 4693 | { label-declarations block-item-list } |
| 4694 | |
| 4695 | nested-declaration: |
| 4696 | __extension__ nested-declaration |
| 4697 | nested-function-definition |
| 4698 | |
| 4699 | label-declarations: |
| 4700 | label-declaration |
| 4701 | label-declarations label-declaration |
| 4702 | |
| 4703 | label-declaration: |
| 4704 | __label__ identifier-list ; |
| 4705 | |
| 4706 | Allowing the mixing of declarations and code is new in C99. The |
| 4707 | GNU syntax also permits (not shown above) labels at the end of |
| 4708 | compound statements, which yield an error. We don't allow labels |
| 4709 | on declarations; this might seem like a natural extension, but |
| 4710 | there would be a conflict between attributes on the label and |
| 4711 | prefix attributes on the declaration. ??? The syntax follows the |
| 4712 | old parser in requiring something after label declarations. |
| 4713 | Although they are erroneous if the labels declared aren't defined, |
| 4714 | is it useful for the syntax to be this way? |
| 4715 | |
| 4716 | OpenACC: |
| 4717 | |
| 4718 | block-item: |
| 4719 | openacc-directive |
| 4720 | |
| 4721 | openacc-directive: |
| 4722 | update-directive |
| 4723 | |
| 4724 | OpenMP: |
| 4725 | |
| 4726 | block-item: |
| 4727 | openmp-directive |
| 4728 | |
| 4729 | openmp-directive: |
| 4730 | barrier-directive |
| 4731 | flush-directive |
| 4732 | taskwait-directive |
| 4733 | taskyield-directive |
| 4734 | cancel-directive |
| 4735 | cancellation-point-directive */ |
| 4736 | |
| 4737 | static tree |
| 4738 | c_parser_compound_statement (c_parser *parser) |
| 4739 | { |
| 4740 | tree stmt; |
| 4741 | location_t brace_loc; |
| 4742 | brace_loc = c_parser_peek_token (parser)->location; |
| 4743 | if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>" )) |
| 4744 | { |
| 4745 | /* Ensure a scope is entered and left anyway to avoid confusion |
| 4746 | if we have just prepared to enter a function body. */ |
| 4747 | stmt = c_begin_compound_stmt (true); |
| 4748 | c_end_compound_stmt (brace_loc, stmt, true); |
| 4749 | return error_mark_node; |
| 4750 | } |
| 4751 | stmt = c_begin_compound_stmt (true); |
| 4752 | c_parser_compound_statement_nostart (parser); |
| 4753 | |
| 4754 | /* If the compound stmt contains array notations, then we expand them. */ |
| 4755 | if (flag_cilkplus && contains_array_notation_expr (stmt)) |
| 4756 | stmt = expand_array_notation_exprs (stmt); |
| 4757 | return c_end_compound_stmt (brace_loc, stmt, true); |
| 4758 | } |
| 4759 | |
| 4760 | /* Parse a compound statement except for the opening brace. This is |
| 4761 | used for parsing both compound statements and statement expressions |
| 4762 | (which follow different paths to handling the opening). */ |
| 4763 | |
| 4764 | static void |
| 4765 | c_parser_compound_statement_nostart (c_parser *parser) |
| 4766 | { |
| 4767 | bool last_stmt = false; |
| 4768 | bool last_label = false; |
| 4769 | bool save_valid_for_pragma = valid_location_for_stdc_pragma_p (); |
| 4770 | location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
| 4771 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 4772 | { |
| 4773 | c_parser_consume_token (parser); |
| 4774 | return; |
| 4775 | } |
| 4776 | mark_valid_location_for_stdc_pragma (true); |
| 4777 | if (c_parser_next_token_is_keyword (parser, RID_LABEL)) |
| 4778 | { |
| 4779 | /* Read zero or more forward-declarations for labels that nested |
| 4780 | functions can jump to. */ |
| 4781 | mark_valid_location_for_stdc_pragma (false); |
| 4782 | while (c_parser_next_token_is_keyword (parser, RID_LABEL)) |
| 4783 | { |
| 4784 | label_loc = c_parser_peek_token (parser)->location; |
| 4785 | c_parser_consume_token (parser); |
| 4786 | /* Any identifiers, including those declared as type names, |
| 4787 | are OK here. */ |
| 4788 | while (true) |
| 4789 | { |
| 4790 | tree label; |
| 4791 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 4792 | { |
| 4793 | c_parser_error (parser, "expected identifier" ); |
| 4794 | break; |
| 4795 | } |
| 4796 | label |
| 4797 | = declare_label (c_parser_peek_token (parser)->value); |
| 4798 | C_DECLARED_LABEL_FLAG (label) = 1; |
| 4799 | add_stmt (build_stmt (label_loc, DECL_EXPR, label)); |
| 4800 | c_parser_consume_token (parser); |
| 4801 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 4802 | c_parser_consume_token (parser); |
| 4803 | else |
| 4804 | break; |
| 4805 | } |
| 4806 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>" ); |
| 4807 | } |
| 4808 | pedwarn (label_loc, OPT_Wpedantic, "ISO C forbids label declarations" ); |
| 4809 | } |
| 4810 | /* We must now have at least one statement, label or declaration. */ |
| 4811 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 4812 | { |
| 4813 | mark_valid_location_for_stdc_pragma (save_valid_for_pragma); |
| 4814 | c_parser_error (parser, "expected declaration or statement" ); |
| 4815 | c_parser_consume_token (parser); |
| 4816 | return; |
| 4817 | } |
| 4818 | while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE)) |
| 4819 | { |
| 4820 | location_t loc = c_parser_peek_token (parser)->location; |
| 4821 | if (c_parser_next_token_is_keyword (parser, RID_CASE) |
| 4822 | || c_parser_next_token_is_keyword (parser, RID_DEFAULT) |
| 4823 | || (c_parser_next_token_is (parser, CPP_NAME) |
| 4824 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) |
| 4825 | { |
| 4826 | if (c_parser_next_token_is_keyword (parser, RID_CASE)) |
| 4827 | label_loc = c_parser_peek_2nd_token (parser)->location; |
| 4828 | else |
| 4829 | label_loc = c_parser_peek_token (parser)->location; |
| 4830 | last_label = true; |
| 4831 | last_stmt = false; |
| 4832 | mark_valid_location_for_stdc_pragma (false); |
| 4833 | c_parser_label (parser); |
| 4834 | } |
| 4835 | else if (!last_label |
| 4836 | && c_parser_next_tokens_start_declaration (parser)) |
| 4837 | { |
| 4838 | last_label = false; |
| 4839 | mark_valid_location_for_stdc_pragma (false); |
| 4840 | bool fallthru_attr_p = false; |
| 4841 | c_parser_declaration_or_fndef (parser, true, true, true, true, |
| 4842 | true, NULL, vNULL, NULL, |
| 4843 | &fallthru_attr_p); |
| 4844 | if (last_stmt && !fallthru_attr_p) |
| 4845 | pedwarn_c90 (loc, OPT_Wdeclaration_after_statement, |
| 4846 | "ISO C90 forbids mixed declarations and code" ); |
| 4847 | last_stmt = fallthru_attr_p; |
| 4848 | } |
| 4849 | else if (!last_label |
| 4850 | && c_parser_next_token_is_keyword (parser, RID_EXTENSION)) |
| 4851 | { |
| 4852 | /* __extension__ can start a declaration, but is also an |
| 4853 | unary operator that can start an expression. Consume all |
| 4854 | but the last of a possible series of __extension__ to |
| 4855 | determine which. */ |
| 4856 | while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD |
| 4857 | && (c_parser_peek_2nd_token (parser)->keyword |
| 4858 | == RID_EXTENSION)) |
| 4859 | c_parser_consume_token (parser); |
| 4860 | if (c_token_starts_declaration (c_parser_peek_2nd_token (parser))) |
| 4861 | { |
| 4862 | int ext; |
| 4863 | ext = disable_extension_diagnostics (); |
| 4864 | c_parser_consume_token (parser); |
| 4865 | last_label = false; |
| 4866 | mark_valid_location_for_stdc_pragma (false); |
| 4867 | c_parser_declaration_or_fndef (parser, true, true, true, true, |
| 4868 | true, NULL, vNULL); |
| 4869 | /* Following the old parser, __extension__ does not |
| 4870 | disable this diagnostic. */ |
| 4871 | restore_extension_diagnostics (ext); |
| 4872 | if (last_stmt) |
| 4873 | pedwarn_c90 (loc, OPT_Wdeclaration_after_statement, |
| 4874 | "ISO C90 forbids mixed declarations and code" ); |
| 4875 | last_stmt = false; |
| 4876 | } |
| 4877 | else |
| 4878 | goto statement; |
| 4879 | } |
| 4880 | else if (c_parser_next_token_is (parser, CPP_PRAGMA)) |
| 4881 | { |
| 4882 | /* External pragmas, and some omp pragmas, are not associated |
| 4883 | with regular c code, and so are not to be considered statements |
| 4884 | syntactically. This ensures that the user doesn't put them |
| 4885 | places that would turn into syntax errors if the directive |
| 4886 | were ignored. */ |
| 4887 | if (c_parser_pragma (parser, |
| 4888 | last_label ? pragma_stmt : pragma_compound, |
| 4889 | NULL)) |
| 4890 | last_label = false, last_stmt = true; |
| 4891 | } |
| 4892 | else if (c_parser_next_token_is (parser, CPP_EOF)) |
| 4893 | { |
| 4894 | mark_valid_location_for_stdc_pragma (save_valid_for_pragma); |
| 4895 | c_parser_error (parser, "expected declaration or statement" ); |
| 4896 | return; |
| 4897 | } |
| 4898 | else if (c_parser_next_token_is_keyword (parser, RID_ELSE)) |
| 4899 | { |
| 4900 | if (parser->in_if_block) |
| 4901 | { |
| 4902 | mark_valid_location_for_stdc_pragma (save_valid_for_pragma); |
| 4903 | error_at (loc, "" "expected %<}%> before %<else%>" ); |
| 4904 | return; |
| 4905 | } |
| 4906 | else |
| 4907 | { |
| 4908 | error_at (loc, "%<else%> without a previous %<if%>" ); |
| 4909 | c_parser_consume_token (parser); |
| 4910 | continue; |
| 4911 | } |
| 4912 | } |
| 4913 | else |
| 4914 | { |
| 4915 | statement: |
| 4916 | last_label = false; |
| 4917 | last_stmt = true; |
| 4918 | mark_valid_location_for_stdc_pragma (false); |
| 4919 | c_parser_statement_after_labels (parser, NULL); |
| 4920 | } |
| 4921 | |
| 4922 | parser->error = false; |
| 4923 | } |
| 4924 | if (last_label) |
| 4925 | error_at (label_loc, "label at end of compound statement" ); |
| 4926 | c_parser_consume_token (parser); |
| 4927 | /* Restore the value we started with. */ |
| 4928 | mark_valid_location_for_stdc_pragma (save_valid_for_pragma); |
| 4929 | } |
| 4930 | |
| 4931 | /* Parse all consecutive labels. */ |
| 4932 | |
| 4933 | static void |
| 4934 | c_parser_all_labels (c_parser *parser) |
| 4935 | { |
| 4936 | while (c_parser_next_token_is_keyword (parser, RID_CASE) |
| 4937 | || c_parser_next_token_is_keyword (parser, RID_DEFAULT) |
| 4938 | || (c_parser_next_token_is (parser, CPP_NAME) |
| 4939 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) |
| 4940 | c_parser_label (parser); |
| 4941 | } |
| 4942 | |
| 4943 | /* Parse a label (C90 6.6.1, C99 6.8.1, C11 6.8.1). |
| 4944 | |
| 4945 | label: |
| 4946 | identifier : attributes[opt] |
| 4947 | case constant-expression : |
| 4948 | default : |
| 4949 | |
| 4950 | GNU extensions: |
| 4951 | |
| 4952 | label: |
| 4953 | case constant-expression ... constant-expression : |
| 4954 | |
| 4955 | The use of attributes on labels is a GNU extension. The syntax in |
| 4956 | GNU C accepts any expressions without commas, non-constant |
| 4957 | expressions being rejected later. */ |
| 4958 | |
| 4959 | static void |
| 4960 | c_parser_label (c_parser *parser) |
| 4961 | { |
| 4962 | location_t loc1 = c_parser_peek_token (parser)->location; |
| 4963 | tree label = NULL_TREE; |
| 4964 | |
| 4965 | /* Remember whether this case or a user-defined label is allowed to fall |
| 4966 | through to. */ |
| 4967 | bool fallthrough_p = c_parser_peek_token (parser)->flags & PREV_FALLTHROUGH; |
| 4968 | |
| 4969 | if (c_parser_next_token_is_keyword (parser, RID_CASE)) |
| 4970 | { |
| 4971 | tree exp1, exp2; |
| 4972 | c_parser_consume_token (parser); |
| 4973 | exp1 = c_parser_expr_no_commas (parser, NULL).value; |
| 4974 | if (c_parser_next_token_is (parser, CPP_COLON)) |
| 4975 | { |
| 4976 | c_parser_consume_token (parser); |
| 4977 | label = do_case (loc1, exp1, NULL_TREE); |
| 4978 | } |
| 4979 | else if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) |
| 4980 | { |
| 4981 | c_parser_consume_token (parser); |
| 4982 | exp2 = c_parser_expr_no_commas (parser, NULL).value; |
| 4983 | if (c_parser_require (parser, CPP_COLON, "expected %<:%>" )) |
| 4984 | label = do_case (loc1, exp1, exp2); |
| 4985 | } |
| 4986 | else |
| 4987 | c_parser_error (parser, "expected %<:%> or %<...%>" ); |
| 4988 | } |
| 4989 | else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)) |
| 4990 | { |
| 4991 | c_parser_consume_token (parser); |
| 4992 | if (c_parser_require (parser, CPP_COLON, "expected %<:%>" )) |
| 4993 | label = do_case (loc1, NULL_TREE, NULL_TREE); |
| 4994 | } |
| 4995 | else |
| 4996 | { |
| 4997 | tree name = c_parser_peek_token (parser)->value; |
| 4998 | tree tlab; |
| 4999 | tree attrs; |
| 5000 | location_t loc2 = c_parser_peek_token (parser)->location; |
| 5001 | gcc_assert (c_parser_next_token_is (parser, CPP_NAME)); |
| 5002 | c_parser_consume_token (parser); |
| 5003 | gcc_assert (c_parser_next_token_is (parser, CPP_COLON)); |
| 5004 | c_parser_consume_token (parser); |
| 5005 | attrs = c_parser_attributes (parser); |
| 5006 | tlab = define_label (loc2, name); |
| 5007 | if (tlab) |
| 5008 | { |
| 5009 | decl_attributes (&tlab, attrs, 0); |
| 5010 | label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab)); |
| 5011 | } |
| 5012 | } |
| 5013 | if (label) |
| 5014 | { |
| 5015 | if (TREE_CODE (label) == LABEL_EXPR) |
| 5016 | FALLTHROUGH_LABEL_P (LABEL_EXPR_LABEL (label)) = fallthrough_p; |
| 5017 | else |
| 5018 | FALLTHROUGH_LABEL_P (CASE_LABEL (label)) = fallthrough_p; |
| 5019 | |
| 5020 | /* Allow '__attribute__((fallthrough));'. */ |
| 5021 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 5022 | { |
| 5023 | location_t loc = c_parser_peek_token (parser)->location; |
| 5024 | tree attrs = c_parser_attributes (parser); |
| 5025 | if (attribute_fallthrough_p (attrs)) |
| 5026 | { |
| 5027 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 5028 | { |
| 5029 | tree fn = build_call_expr_internal_loc (loc, |
| 5030 | IFN_FALLTHROUGH, |
| 5031 | void_type_node, 0); |
| 5032 | add_stmt (fn); |
| 5033 | } |
| 5034 | else |
| 5035 | warning_at (loc, OPT_Wattributes, "%<fallthrough%> attribute " |
| 5036 | "not followed by %<;%>" ); |
| 5037 | } |
| 5038 | else if (attrs != NULL_TREE) |
| 5039 | warning_at (loc, OPT_Wattributes, "only attribute %<fallthrough%>" |
| 5040 | " can be applied to a null statement" ); |
| 5041 | } |
| 5042 | if (c_parser_next_tokens_start_declaration (parser)) |
| 5043 | { |
| 5044 | error_at (c_parser_peek_token (parser)->location, |
| 5045 | "a label can only be part of a statement and " |
| 5046 | "a declaration is not a statement" ); |
| 5047 | c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false, |
| 5048 | /*static_assert_ok*/ true, |
| 5049 | /*empty_ok*/ true, /*nested*/ true, |
| 5050 | /*start_attr_ok*/ true, NULL, |
| 5051 | vNULL); |
| 5052 | } |
| 5053 | } |
| 5054 | } |
| 5055 | |
| 5056 | /* Parse a statement (C90 6.6, C99 6.8, C11 6.8). |
| 5057 | |
| 5058 | statement: |
| 5059 | labeled-statement |
| 5060 | compound-statement |
| 5061 | expression-statement |
| 5062 | selection-statement |
| 5063 | iteration-statement |
| 5064 | jump-statement |
| 5065 | |
| 5066 | labeled-statement: |
| 5067 | label statement |
| 5068 | |
| 5069 | expression-statement: |
| 5070 | expression[opt] ; |
| 5071 | |
| 5072 | selection-statement: |
| 5073 | if-statement |
| 5074 | switch-statement |
| 5075 | |
| 5076 | iteration-statement: |
| 5077 | while-statement |
| 5078 | do-statement |
| 5079 | for-statement |
| 5080 | |
| 5081 | jump-statement: |
| 5082 | goto identifier ; |
| 5083 | continue ; |
| 5084 | break ; |
| 5085 | return expression[opt] ; |
| 5086 | |
| 5087 | GNU extensions: |
| 5088 | |
| 5089 | statement: |
| 5090 | asm-statement |
| 5091 | |
| 5092 | jump-statement: |
| 5093 | goto * expression ; |
| 5094 | |
| 5095 | expression-statement: |
| 5096 | attributes ; |
| 5097 | |
| 5098 | Objective-C: |
| 5099 | |
| 5100 | statement: |
| 5101 | objc-throw-statement |
| 5102 | objc-try-catch-statement |
| 5103 | objc-synchronized-statement |
| 5104 | |
| 5105 | objc-throw-statement: |
| 5106 | @throw expression ; |
| 5107 | @throw ; |
| 5108 | |
| 5109 | OpenACC: |
| 5110 | |
| 5111 | statement: |
| 5112 | openacc-construct |
| 5113 | |
| 5114 | openacc-construct: |
| 5115 | parallel-construct |
| 5116 | kernels-construct |
| 5117 | data-construct |
| 5118 | loop-construct |
| 5119 | |
| 5120 | parallel-construct: |
| 5121 | parallel-directive structured-block |
| 5122 | |
| 5123 | kernels-construct: |
| 5124 | kernels-directive structured-block |
| 5125 | |
| 5126 | data-construct: |
| 5127 | data-directive structured-block |
| 5128 | |
| 5129 | loop-construct: |
| 5130 | loop-directive structured-block |
| 5131 | |
| 5132 | OpenMP: |
| 5133 | |
| 5134 | statement: |
| 5135 | openmp-construct |
| 5136 | |
| 5137 | openmp-construct: |
| 5138 | parallel-construct |
| 5139 | for-construct |
| 5140 | simd-construct |
| 5141 | for-simd-construct |
| 5142 | sections-construct |
| 5143 | single-construct |
| 5144 | parallel-for-construct |
| 5145 | parallel-for-simd-construct |
| 5146 | parallel-sections-construct |
| 5147 | master-construct |
| 5148 | critical-construct |
| 5149 | atomic-construct |
| 5150 | ordered-construct |
| 5151 | |
| 5152 | parallel-construct: |
| 5153 | parallel-directive structured-block |
| 5154 | |
| 5155 | for-construct: |
| 5156 | for-directive iteration-statement |
| 5157 | |
| 5158 | simd-construct: |
| 5159 | simd-directive iteration-statements |
| 5160 | |
| 5161 | for-simd-construct: |
| 5162 | for-simd-directive iteration-statements |
| 5163 | |
| 5164 | sections-construct: |
| 5165 | sections-directive section-scope |
| 5166 | |
| 5167 | single-construct: |
| 5168 | single-directive structured-block |
| 5169 | |
| 5170 | parallel-for-construct: |
| 5171 | parallel-for-directive iteration-statement |
| 5172 | |
| 5173 | parallel-for-simd-construct: |
| 5174 | parallel-for-simd-directive iteration-statement |
| 5175 | |
| 5176 | parallel-sections-construct: |
| 5177 | parallel-sections-directive section-scope |
| 5178 | |
| 5179 | master-construct: |
| 5180 | master-directive structured-block |
| 5181 | |
| 5182 | critical-construct: |
| 5183 | critical-directive structured-block |
| 5184 | |
| 5185 | atomic-construct: |
| 5186 | atomic-directive expression-statement |
| 5187 | |
| 5188 | ordered-construct: |
| 5189 | ordered-directive structured-block |
| 5190 | |
| 5191 | Transactional Memory: |
| 5192 | |
| 5193 | statement: |
| 5194 | transaction-statement |
| 5195 | transaction-cancel-statement |
| 5196 | |
| 5197 | IF_P is used to track whether there's a (possibly labeled) if statement |
| 5198 | which is not enclosed in braces and has an else clause. This is used to |
| 5199 | implement -Wparentheses. */ |
| 5200 | |
| 5201 | static void |
| 5202 | c_parser_statement (c_parser *parser, bool *if_p) |
| 5203 | { |
| 5204 | c_parser_all_labels (parser); |
| 5205 | c_parser_statement_after_labels (parser, if_p, NULL); |
| 5206 | } |
| 5207 | |
| 5208 | /* Parse a statement, other than a labeled statement. CHAIN is a vector |
| 5209 | of if-else-if conditions. |
| 5210 | |
| 5211 | IF_P is used to track whether there's a (possibly labeled) if statement |
| 5212 | which is not enclosed in braces and has an else clause. This is used to |
| 5213 | implement -Wparentheses. */ |
| 5214 | |
| 5215 | static void |
| 5216 | c_parser_statement_after_labels (c_parser *parser, bool *if_p, |
| 5217 | vec<tree> *chain) |
| 5218 | { |
| 5219 | location_t loc = c_parser_peek_token (parser)->location; |
| 5220 | tree stmt = NULL_TREE; |
| 5221 | bool in_if_block = parser->in_if_block; |
| 5222 | parser->in_if_block = false; |
| 5223 | if (if_p != NULL) |
| 5224 | *if_p = false; |
| 5225 | switch (c_parser_peek_token (parser)->type) |
| 5226 | { |
| 5227 | case CPP_OPEN_BRACE: |
| 5228 | add_stmt (c_parser_compound_statement (parser)); |
| 5229 | break; |
| 5230 | case CPP_KEYWORD: |
| 5231 | switch (c_parser_peek_token (parser)->keyword) |
| 5232 | { |
| 5233 | case RID_IF: |
| 5234 | c_parser_if_statement (parser, if_p, chain); |
| 5235 | break; |
| 5236 | case RID_SWITCH: |
| 5237 | c_parser_switch_statement (parser, if_p); |
| 5238 | break; |
| 5239 | case RID_WHILE: |
| 5240 | c_parser_while_statement (parser, false, if_p); |
| 5241 | break; |
| 5242 | case RID_DO: |
| 5243 | c_parser_do_statement (parser, false); |
| 5244 | break; |
| 5245 | case RID_FOR: |
| 5246 | c_parser_for_statement (parser, false, if_p); |
| 5247 | break; |
| 5248 | case RID_CILK_FOR: |
| 5249 | if (!flag_cilkplus) |
| 5250 | { |
| 5251 | error_at (c_parser_peek_token (parser)->location, |
| 5252 | "-fcilkplus must be enabled to use %<_Cilk_for%>" ); |
| 5253 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 5254 | } |
| 5255 | else |
| 5256 | c_parser_cilk_for (parser, integer_zero_node, if_p); |
| 5257 | break; |
| 5258 | case RID_CILK_SYNC: |
| 5259 | c_parser_consume_token (parser); |
| 5260 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>" ); |
| 5261 | if (!flag_cilkplus) |
| 5262 | error_at (loc, "-fcilkplus must be enabled to use %<_Cilk_sync%>" ); |
| 5263 | else |
| 5264 | add_stmt (build_cilk_sync ()); |
| 5265 | break; |
| 5266 | case RID_GOTO: |
| 5267 | c_parser_consume_token (parser); |
| 5268 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 5269 | { |
| 5270 | stmt = c_finish_goto_label (loc, |
| 5271 | c_parser_peek_token (parser)->value); |
| 5272 | c_parser_consume_token (parser); |
| 5273 | } |
| 5274 | else if (c_parser_next_token_is (parser, CPP_MULT)) |
| 5275 | { |
| 5276 | struct c_expr val; |
| 5277 | |
| 5278 | c_parser_consume_token (parser); |
| 5279 | val = c_parser_expression (parser); |
| 5280 | if (check_no_cilk (val.value, |
| 5281 | "Cilk array notation cannot be used as a computed goto expression" , |
| 5282 | "%<_Cilk_spawn%> statement cannot be used as a computed goto expression" , |
| 5283 | loc)) |
| 5284 | val.value = error_mark_node; |
| 5285 | val = convert_lvalue_to_rvalue (loc, val, false, true); |
| 5286 | stmt = c_finish_goto_ptr (loc, val.value); |
| 5287 | } |
| 5288 | else |
| 5289 | c_parser_error (parser, "expected identifier or %<*%>" ); |
| 5290 | goto expect_semicolon; |
| 5291 | case RID_CONTINUE: |
| 5292 | c_parser_consume_token (parser); |
| 5293 | stmt = c_finish_bc_stmt (loc, &c_cont_label, false); |
| 5294 | goto expect_semicolon; |
| 5295 | case RID_BREAK: |
| 5296 | c_parser_consume_token (parser); |
| 5297 | stmt = c_finish_bc_stmt (loc, &c_break_label, true); |
| 5298 | goto expect_semicolon; |
| 5299 | case RID_RETURN: |
| 5300 | c_parser_consume_token (parser); |
| 5301 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 5302 | { |
| 5303 | stmt = c_finish_return (loc, NULL_TREE, NULL_TREE); |
| 5304 | c_parser_consume_token (parser); |
| 5305 | } |
| 5306 | else |
| 5307 | { |
| 5308 | location_t xloc = c_parser_peek_token (parser)->location; |
| 5309 | struct c_expr expr = c_parser_expression_conv (parser); |
| 5310 | mark_exp_read (expr.value); |
| 5311 | stmt = c_finish_return (EXPR_LOC_OR_LOC (expr.value, xloc), |
| 5312 | expr.value, expr.original_type); |
| 5313 | goto expect_semicolon; |
| 5314 | } |
| 5315 | break; |
| 5316 | case RID_ASM: |
| 5317 | stmt = c_parser_asm_statement (parser); |
| 5318 | break; |
| 5319 | case RID_TRANSACTION_ATOMIC: |
| 5320 | case RID_TRANSACTION_RELAXED: |
| 5321 | stmt = c_parser_transaction (parser, |
| 5322 | c_parser_peek_token (parser)->keyword); |
| 5323 | break; |
| 5324 | case RID_TRANSACTION_CANCEL: |
| 5325 | stmt = c_parser_transaction_cancel (parser); |
| 5326 | goto expect_semicolon; |
| 5327 | case RID_AT_THROW: |
| 5328 | gcc_assert (c_dialect_objc ()); |
| 5329 | c_parser_consume_token (parser); |
| 5330 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 5331 | { |
| 5332 | stmt = objc_build_throw_stmt (loc, NULL_TREE); |
| 5333 | c_parser_consume_token (parser); |
| 5334 | } |
| 5335 | else |
| 5336 | { |
| 5337 | struct c_expr expr = c_parser_expression (parser); |
| 5338 | expr = convert_lvalue_to_rvalue (loc, expr, false, false); |
| 5339 | if (check_no_cilk (expr.value, |
| 5340 | "Cilk array notation cannot be used for a throw expression" , |
| 5341 | "%<_Cilk_spawn%> statement cannot be used for a throw expression" )) |
| 5342 | expr.value = error_mark_node; |
| 5343 | else |
| 5344 | { |
| 5345 | expr.value = c_fully_fold (expr.value, false, NULL); |
| 5346 | stmt = objc_build_throw_stmt (loc, expr.value); |
| 5347 | } |
| 5348 | goto expect_semicolon; |
| 5349 | } |
| 5350 | break; |
| 5351 | case RID_AT_TRY: |
| 5352 | gcc_assert (c_dialect_objc ()); |
| 5353 | c_parser_objc_try_catch_finally_statement (parser); |
| 5354 | break; |
| 5355 | case RID_AT_SYNCHRONIZED: |
| 5356 | gcc_assert (c_dialect_objc ()); |
| 5357 | c_parser_objc_synchronized_statement (parser); |
| 5358 | break; |
| 5359 | case RID_ATTRIBUTE: |
| 5360 | { |
| 5361 | /* Allow '__attribute__((fallthrough));'. */ |
| 5362 | tree attrs = c_parser_attributes (parser); |
| 5363 | if (attribute_fallthrough_p (attrs)) |
| 5364 | { |
| 5365 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 5366 | { |
| 5367 | tree fn = build_call_expr_internal_loc (loc, |
| 5368 | IFN_FALLTHROUGH, |
| 5369 | void_type_node, 0); |
| 5370 | add_stmt (fn); |
| 5371 | /* Eat the ';'. */ |
| 5372 | c_parser_consume_token (parser); |
| 5373 | } |
| 5374 | else |
| 5375 | warning_at (loc, OPT_Wattributes, |
| 5376 | "%<fallthrough%> attribute not followed " |
| 5377 | "by %<;%>" ); |
| 5378 | } |
| 5379 | else if (attrs != NULL_TREE) |
| 5380 | warning_at (loc, OPT_Wattributes, "only attribute %<fallthrough%>" |
| 5381 | " can be applied to a null statement" ); |
| 5382 | break; |
| 5383 | } |
| 5384 | default: |
| 5385 | goto expr_stmt; |
| 5386 | } |
| 5387 | break; |
| 5388 | case CPP_SEMICOLON: |
| 5389 | c_parser_consume_token (parser); |
| 5390 | break; |
| 5391 | case CPP_CLOSE_PAREN: |
| 5392 | case CPP_CLOSE_SQUARE: |
| 5393 | /* Avoid infinite loop in error recovery: |
| 5394 | c_parser_skip_until_found stops at a closing nesting |
| 5395 | delimiter without consuming it, but here we need to consume |
| 5396 | it to proceed further. */ |
| 5397 | c_parser_error (parser, "expected statement" ); |
| 5398 | c_parser_consume_token (parser); |
| 5399 | break; |
| 5400 | case CPP_PRAGMA: |
| 5401 | c_parser_pragma (parser, pragma_stmt, if_p); |
| 5402 | break; |
| 5403 | default: |
| 5404 | expr_stmt: |
| 5405 | stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value); |
| 5406 | expect_semicolon: |
| 5407 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>" ); |
| 5408 | break; |
| 5409 | } |
| 5410 | /* Two cases cannot and do not have line numbers associated: If stmt |
| 5411 | is degenerate, such as "2;", then stmt is an INTEGER_CST, which |
| 5412 | cannot hold line numbers. But that's OK because the statement |
| 5413 | will either be changed to a MODIFY_EXPR during gimplification of |
| 5414 | the statement expr, or discarded. If stmt was compound, but |
| 5415 | without new variables, we will have skipped the creation of a |
| 5416 | BIND and will have a bare STATEMENT_LIST. But that's OK because |
| 5417 | (recursively) all of the component statements should already have |
| 5418 | line numbers assigned. ??? Can we discard no-op statements |
| 5419 | earlier? */ |
| 5420 | if (EXPR_LOCATION (stmt) == UNKNOWN_LOCATION) |
| 5421 | protected_set_expr_location (stmt, loc); |
| 5422 | |
| 5423 | parser->in_if_block = in_if_block; |
| 5424 | } |
| 5425 | |
| 5426 | /* Parse the condition from an if, do, while or for statements. */ |
| 5427 | |
| 5428 | static tree |
| 5429 | c_parser_condition (c_parser *parser) |
| 5430 | { |
| 5431 | location_t loc = c_parser_peek_token (parser)->location; |
| 5432 | tree cond; |
| 5433 | cond = c_parser_expression_conv (parser).value; |
| 5434 | cond = c_objc_common_truthvalue_conversion (loc, cond); |
| 5435 | cond = c_fully_fold (cond, false, NULL); |
| 5436 | if (warn_sequence_point) |
| 5437 | verify_sequence_points (cond); |
| 5438 | return cond; |
| 5439 | } |
| 5440 | |
| 5441 | /* Parse a parenthesized condition from an if, do or while statement. |
| 5442 | |
| 5443 | condition: |
| 5444 | ( expression ) |
| 5445 | */ |
| 5446 | static tree |
| 5447 | c_parser_paren_condition (c_parser *parser) |
| 5448 | { |
| 5449 | tree cond; |
| 5450 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 5451 | return error_mark_node; |
| 5452 | cond = c_parser_condition (parser); |
| 5453 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 5454 | return cond; |
| 5455 | } |
| 5456 | |
| 5457 | /* Parse a statement which is a block in C99. |
| 5458 | |
| 5459 | IF_P is used to track whether there's a (possibly labeled) if statement |
| 5460 | which is not enclosed in braces and has an else clause. This is used to |
| 5461 | implement -Wparentheses. */ |
| 5462 | |
| 5463 | static tree |
| 5464 | c_parser_c99_block_statement (c_parser *parser, bool *if_p) |
| 5465 | { |
| 5466 | tree block = c_begin_compound_stmt (flag_isoc99); |
| 5467 | location_t loc = c_parser_peek_token (parser)->location; |
| 5468 | c_parser_statement (parser, if_p); |
| 5469 | return c_end_compound_stmt (loc, block, flag_isoc99); |
| 5470 | } |
| 5471 | |
| 5472 | /* Parse the body of an if statement. This is just parsing a |
| 5473 | statement but (a) it is a block in C99, (b) we track whether the |
| 5474 | body is an if statement for the sake of -Wparentheses warnings, (c) |
| 5475 | we handle an empty body specially for the sake of -Wempty-body |
| 5476 | warnings, and (d) we call parser_compound_statement directly |
| 5477 | because c_parser_statement_after_labels resets |
| 5478 | parser->in_if_block. |
| 5479 | |
| 5480 | IF_P is used to track whether there's a (possibly labeled) if statement |
| 5481 | which is not enclosed in braces and has an else clause. This is used to |
| 5482 | implement -Wparentheses. */ |
| 5483 | |
| 5484 | static tree |
| 5485 | c_parser_if_body (c_parser *parser, bool *if_p, |
| 5486 | const token_indent_info &if_tinfo) |
| 5487 | { |
| 5488 | tree block = c_begin_compound_stmt (flag_isoc99); |
| 5489 | location_t body_loc = c_parser_peek_token (parser)->location; |
| 5490 | token_indent_info body_tinfo |
| 5491 | = get_token_indent_info (c_parser_peek_token (parser)); |
| 5492 | |
| 5493 | c_parser_all_labels (parser); |
| 5494 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 5495 | { |
| 5496 | location_t loc = c_parser_peek_token (parser)->location; |
| 5497 | add_stmt (build_empty_stmt (loc)); |
| 5498 | c_parser_consume_token (parser); |
| 5499 | if (!c_parser_next_token_is_keyword (parser, RID_ELSE)) |
| 5500 | warning_at (loc, OPT_Wempty_body, |
| 5501 | "suggest braces around empty body in an %<if%> statement" ); |
| 5502 | } |
| 5503 | else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 5504 | add_stmt (c_parser_compound_statement (parser)); |
| 5505 | else |
| 5506 | c_parser_statement_after_labels (parser, if_p); |
| 5507 | |
| 5508 | token_indent_info next_tinfo |
| 5509 | = get_token_indent_info (c_parser_peek_token (parser)); |
| 5510 | warn_for_misleading_indentation (if_tinfo, body_tinfo, next_tinfo); |
| 5511 | |
| 5512 | return c_end_compound_stmt (body_loc, block, flag_isoc99); |
| 5513 | } |
| 5514 | |
| 5515 | /* Parse the else body of an if statement. This is just parsing a |
| 5516 | statement but (a) it is a block in C99, (b) we handle an empty body |
| 5517 | specially for the sake of -Wempty-body warnings. CHAIN is a vector |
| 5518 | of if-else-if conditions. */ |
| 5519 | |
| 5520 | static tree |
| 5521 | c_parser_else_body (c_parser *parser, const token_indent_info &else_tinfo, |
| 5522 | vec<tree> *chain) |
| 5523 | { |
| 5524 | location_t body_loc = c_parser_peek_token (parser)->location; |
| 5525 | tree block = c_begin_compound_stmt (flag_isoc99); |
| 5526 | token_indent_info body_tinfo |
| 5527 | = get_token_indent_info (c_parser_peek_token (parser)); |
| 5528 | |
| 5529 | c_parser_all_labels (parser); |
| 5530 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 5531 | { |
| 5532 | location_t loc = c_parser_peek_token (parser)->location; |
| 5533 | warning_at (loc, |
| 5534 | OPT_Wempty_body, |
| 5535 | "suggest braces around empty body in an %<else%> statement" ); |
| 5536 | add_stmt (build_empty_stmt (loc)); |
| 5537 | c_parser_consume_token (parser); |
| 5538 | } |
| 5539 | else |
| 5540 | c_parser_statement_after_labels (parser, NULL, chain); |
| 5541 | |
| 5542 | token_indent_info next_tinfo |
| 5543 | = get_token_indent_info (c_parser_peek_token (parser)); |
| 5544 | warn_for_misleading_indentation (else_tinfo, body_tinfo, next_tinfo); |
| 5545 | |
| 5546 | return c_end_compound_stmt (body_loc, block, flag_isoc99); |
| 5547 | } |
| 5548 | |
| 5549 | /* We might need to reclassify any previously-lexed identifier, e.g. |
| 5550 | when we've left a for loop with an if-statement without else in the |
| 5551 | body - we might have used a wrong scope for the token. See PR67784. */ |
| 5552 | |
| 5553 | static void |
| 5554 | c_parser_maybe_reclassify_token (c_parser *parser) |
| 5555 | { |
| 5556 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 5557 | { |
| 5558 | c_token *token = c_parser_peek_token (parser); |
| 5559 | |
| 5560 | if (token->id_kind != C_ID_CLASSNAME) |
| 5561 | { |
| 5562 | tree decl = lookup_name (token->value); |
| 5563 | |
| 5564 | token->id_kind = C_ID_ID; |
| 5565 | if (decl) |
| 5566 | { |
| 5567 | if (TREE_CODE (decl) == TYPE_DECL) |
| 5568 | token->id_kind = C_ID_TYPENAME; |
| 5569 | } |
| 5570 | else if (c_dialect_objc ()) |
| 5571 | { |
| 5572 | tree objc_interface_decl = objc_is_class_name (token->value); |
| 5573 | /* Objective-C class names are in the same namespace as |
| 5574 | variables and typedefs, and hence are shadowed by local |
| 5575 | declarations. */ |
| 5576 | if (objc_interface_decl) |
| 5577 | { |
| 5578 | token->value = objc_interface_decl; |
| 5579 | token->id_kind = C_ID_CLASSNAME; |
| 5580 | } |
| 5581 | } |
| 5582 | } |
| 5583 | } |
| 5584 | } |
| 5585 | |
| 5586 | /* Parse an if statement (C90 6.6.4, C99 6.8.4, C11 6.8.4). |
| 5587 | |
| 5588 | if-statement: |
| 5589 | if ( expression ) statement |
| 5590 | if ( expression ) statement else statement |
| 5591 | |
| 5592 | CHAIN is a vector of if-else-if conditions. |
| 5593 | IF_P is used to track whether there's a (possibly labeled) if statement |
| 5594 | which is not enclosed in braces and has an else clause. This is used to |
| 5595 | implement -Wparentheses. */ |
| 5596 | |
| 5597 | static void |
| 5598 | c_parser_if_statement (c_parser *parser, bool *if_p, vec<tree> *chain) |
| 5599 | { |
| 5600 | tree block; |
| 5601 | location_t loc; |
| 5602 | tree cond; |
| 5603 | bool nested_if = false; |
| 5604 | tree first_body, second_body; |
| 5605 | bool in_if_block; |
| 5606 | tree if_stmt; |
| 5607 | |
| 5608 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF)); |
| 5609 | token_indent_info if_tinfo |
| 5610 | = get_token_indent_info (c_parser_peek_token (parser)); |
| 5611 | c_parser_consume_token (parser); |
| 5612 | block = c_begin_compound_stmt (flag_isoc99); |
| 5613 | loc = c_parser_peek_token (parser)->location; |
| 5614 | cond = c_parser_paren_condition (parser); |
| 5615 | if (flag_cilkplus && contains_cilk_spawn_stmt (cond)) |
| 5616 | { |
| 5617 | error_at (loc, "if statement cannot contain %<Cilk_spawn%>" ); |
| 5618 | cond = error_mark_node; |
| 5619 | } |
| 5620 | in_if_block = parser->in_if_block; |
| 5621 | parser->in_if_block = true; |
| 5622 | first_body = c_parser_if_body (parser, &nested_if, if_tinfo); |
| 5623 | parser->in_if_block = in_if_block; |
| 5624 | |
| 5625 | if (warn_duplicated_cond) |
| 5626 | warn_duplicated_cond_add_or_warn (EXPR_LOCATION (cond), cond, &chain); |
| 5627 | |
| 5628 | if (c_parser_next_token_is_keyword (parser, RID_ELSE)) |
| 5629 | { |
| 5630 | token_indent_info else_tinfo |
| 5631 | = get_token_indent_info (c_parser_peek_token (parser)); |
| 5632 | c_parser_consume_token (parser); |
| 5633 | if (warn_duplicated_cond) |
| 5634 | { |
| 5635 | if (c_parser_next_token_is_keyword (parser, RID_IF) |
| 5636 | && chain == NULL) |
| 5637 | { |
| 5638 | /* We've got "if (COND) else if (COND2)". Start the |
| 5639 | condition chain and add COND as the first element. */ |
| 5640 | chain = new vec<tree> (); |
| 5641 | if (!CONSTANT_CLASS_P (cond) && !TREE_SIDE_EFFECTS (cond)) |
| 5642 | chain->safe_push (cond); |
| 5643 | } |
| 5644 | else if (!c_parser_next_token_is_keyword (parser, RID_IF)) |
| 5645 | { |
| 5646 | /* This is if-else without subsequent if. Zap the condition |
| 5647 | chain; we would have already warned at this point. */ |
| 5648 | delete chain; |
| 5649 | chain = NULL; |
| 5650 | } |
| 5651 | } |
| 5652 | second_body = c_parser_else_body (parser, else_tinfo, chain); |
| 5653 | /* Set IF_P to true to indicate that this if statement has an |
| 5654 | else clause. This may trigger the Wparentheses warning |
| 5655 | below when we get back up to the parent if statement. */ |
| 5656 | if (if_p != NULL) |
| 5657 | *if_p = true; |
| 5658 | } |
| 5659 | else |
| 5660 | { |
| 5661 | second_body = NULL_TREE; |
| 5662 | |
| 5663 | /* Diagnose an ambiguous else if if-then-else is nested inside |
| 5664 | if-then. */ |
| 5665 | if (nested_if) |
| 5666 | warning_at (loc, OPT_Wdangling_else, |
| 5667 | "suggest explicit braces to avoid ambiguous %<else%>" ); |
| 5668 | |
| 5669 | if (warn_duplicated_cond) |
| 5670 | { |
| 5671 | /* This if statement does not have an else clause. We don't |
| 5672 | need the condition chain anymore. */ |
| 5673 | delete chain; |
| 5674 | chain = NULL; |
| 5675 | } |
| 5676 | } |
| 5677 | c_finish_if_stmt (loc, cond, first_body, second_body); |
| 5678 | if_stmt = c_end_compound_stmt (loc, block, flag_isoc99); |
| 5679 | |
| 5680 | /* If the if statement contains array notations, then we expand them. */ |
| 5681 | if (flag_cilkplus && contains_array_notation_expr (if_stmt)) |
| 5682 | if_stmt = fix_conditional_array_notations (if_stmt); |
| 5683 | add_stmt (if_stmt); |
| 5684 | c_parser_maybe_reclassify_token (parser); |
| 5685 | } |
| 5686 | |
| 5687 | /* Parse a switch statement (C90 6.6.4, C99 6.8.4, C11 6.8.4). |
| 5688 | |
| 5689 | switch-statement: |
| 5690 | switch (expression) statement |
| 5691 | */ |
| 5692 | |
| 5693 | static void |
| 5694 | c_parser_switch_statement (c_parser *parser, bool *if_p) |
| 5695 | { |
| 5696 | struct c_expr ce; |
| 5697 | tree block, expr, body, save_break; |
| 5698 | location_t switch_loc = c_parser_peek_token (parser)->location; |
| 5699 | location_t switch_cond_loc; |
| 5700 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH)); |
| 5701 | c_parser_consume_token (parser); |
| 5702 | block = c_begin_compound_stmt (flag_isoc99); |
| 5703 | bool explicit_cast_p = false; |
| 5704 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 5705 | { |
| 5706 | switch_cond_loc = c_parser_peek_token (parser)->location; |
| 5707 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) |
| 5708 | && c_token_starts_typename (c_parser_peek_2nd_token (parser))) |
| 5709 | explicit_cast_p = true; |
| 5710 | ce = c_parser_expression (parser); |
| 5711 | ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, false); |
| 5712 | expr = ce.value; |
| 5713 | /* ??? expr has no valid location? */ |
| 5714 | if (check_no_cilk (expr, |
| 5715 | "Cilk array notation cannot be used as a condition for switch statement" , |
| 5716 | "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement" , |
| 5717 | switch_cond_loc)) |
| 5718 | expr = error_mark_node; |
| 5719 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 5720 | } |
| 5721 | else |
| 5722 | { |
| 5723 | switch_cond_loc = UNKNOWN_LOCATION; |
| 5724 | expr = error_mark_node; |
| 5725 | ce.original_type = error_mark_node; |
| 5726 | } |
| 5727 | c_start_case (switch_loc, switch_cond_loc, expr, explicit_cast_p); |
| 5728 | save_break = c_break_label; |
| 5729 | c_break_label = NULL_TREE; |
| 5730 | body = c_parser_c99_block_statement (parser, if_p); |
| 5731 | c_finish_case (body, ce.original_type); |
| 5732 | if (c_break_label) |
| 5733 | { |
| 5734 | location_t here = c_parser_peek_token (parser)->location; |
| 5735 | tree t = build1 (LABEL_EXPR, void_type_node, c_break_label); |
| 5736 | SET_EXPR_LOCATION (t, here); |
| 5737 | add_stmt (t); |
| 5738 | } |
| 5739 | c_break_label = save_break; |
| 5740 | add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99)); |
| 5741 | c_parser_maybe_reclassify_token (parser); |
| 5742 | } |
| 5743 | |
| 5744 | /* Parse a while statement (C90 6.6.5, C99 6.8.5, C11 6.8.5). |
| 5745 | |
| 5746 | while-statement: |
| 5747 | while (expression) statement |
| 5748 | |
| 5749 | IF_P is used to track whether there's a (possibly labeled) if statement |
| 5750 | which is not enclosed in braces and has an else clause. This is used to |
| 5751 | implement -Wparentheses. */ |
| 5752 | |
| 5753 | static void |
| 5754 | c_parser_while_statement (c_parser *parser, bool ivdep, bool *if_p) |
| 5755 | { |
| 5756 | tree block, cond, body, save_break, save_cont; |
| 5757 | location_t loc; |
| 5758 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE)); |
| 5759 | token_indent_info while_tinfo |
| 5760 | = get_token_indent_info (c_parser_peek_token (parser)); |
| 5761 | c_parser_consume_token (parser); |
| 5762 | block = c_begin_compound_stmt (flag_isoc99); |
| 5763 | loc = c_parser_peek_token (parser)->location; |
| 5764 | cond = c_parser_paren_condition (parser); |
| 5765 | if (check_no_cilk (cond, |
| 5766 | "Cilk array notation cannot be used as a condition for while statement" , |
| 5767 | "%<_Cilk_spawn%> statement cannot be used as a condition for while statement" )) |
| 5768 | cond = error_mark_node; |
| 5769 | if (ivdep && cond != error_mark_node) |
| 5770 | cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, |
| 5771 | build_int_cst (integer_type_node, |
| 5772 | annot_expr_ivdep_kind)); |
| 5773 | save_break = c_break_label; |
| 5774 | c_break_label = NULL_TREE; |
| 5775 | save_cont = c_cont_label; |
| 5776 | c_cont_label = NULL_TREE; |
| 5777 | |
| 5778 | token_indent_info body_tinfo |
| 5779 | = get_token_indent_info (c_parser_peek_token (parser)); |
| 5780 | |
| 5781 | body = c_parser_c99_block_statement (parser, if_p); |
| 5782 | c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true); |
| 5783 | add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); |
| 5784 | c_parser_maybe_reclassify_token (parser); |
| 5785 | |
| 5786 | token_indent_info next_tinfo |
| 5787 | = get_token_indent_info (c_parser_peek_token (parser)); |
| 5788 | warn_for_misleading_indentation (while_tinfo, body_tinfo, next_tinfo); |
| 5789 | |
| 5790 | c_break_label = save_break; |
| 5791 | c_cont_label = save_cont; |
| 5792 | } |
| 5793 | |
| 5794 | /* Parse a do statement (C90 6.6.5, C99 6.8.5, C11 6.8.5). |
| 5795 | |
| 5796 | do-statement: |
| 5797 | do statement while ( expression ) ; |
| 5798 | */ |
| 5799 | |
| 5800 | static void |
| 5801 | c_parser_do_statement (c_parser *parser, bool ivdep) |
| 5802 | { |
| 5803 | tree block, cond, body, save_break, save_cont, new_break, new_cont; |
| 5804 | location_t loc; |
| 5805 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO)); |
| 5806 | c_parser_consume_token (parser); |
| 5807 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 5808 | warning_at (c_parser_peek_token (parser)->location, |
| 5809 | OPT_Wempty_body, |
| 5810 | "suggest braces around empty body in %<do%> statement" ); |
| 5811 | block = c_begin_compound_stmt (flag_isoc99); |
| 5812 | loc = c_parser_peek_token (parser)->location; |
| 5813 | save_break = c_break_label; |
| 5814 | c_break_label = NULL_TREE; |
| 5815 | save_cont = c_cont_label; |
| 5816 | c_cont_label = NULL_TREE; |
| 5817 | body = c_parser_c99_block_statement (parser, NULL); |
| 5818 | c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>" ); |
| 5819 | new_break = c_break_label; |
| 5820 | c_break_label = save_break; |
| 5821 | new_cont = c_cont_label; |
| 5822 | c_cont_label = save_cont; |
| 5823 | cond = c_parser_paren_condition (parser); |
| 5824 | if (check_no_cilk (cond, |
| 5825 | "Cilk array notation cannot be used as a condition for a do-while statement" , |
| 5826 | "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement" )) |
| 5827 | cond = error_mark_node; |
| 5828 | if (ivdep && cond != error_mark_node) |
| 5829 | cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, |
| 5830 | build_int_cst (integer_type_node, |
| 5831 | annot_expr_ivdep_kind)); |
| 5832 | if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>" )) |
| 5833 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 5834 | c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false); |
| 5835 | add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); |
| 5836 | } |
| 5837 | |
| 5838 | /* Parse a for statement (C90 6.6.5, C99 6.8.5, C11 6.8.5). |
| 5839 | |
| 5840 | for-statement: |
| 5841 | for ( expression[opt] ; expression[opt] ; expression[opt] ) statement |
| 5842 | for ( nested-declaration expression[opt] ; expression[opt] ) statement |
| 5843 | |
| 5844 | The form with a declaration is new in C99. |
| 5845 | |
| 5846 | ??? In accordance with the old parser, the declaration may be a |
| 5847 | nested function, which is then rejected in check_for_loop_decls, |
| 5848 | but does it make any sense for this to be included in the grammar? |
| 5849 | Note in particular that the nested function does not include a |
| 5850 | trailing ';', whereas the "declaration" production includes one. |
| 5851 | Also, can we reject bad declarations earlier and cheaper than |
| 5852 | check_for_loop_decls? |
| 5853 | |
| 5854 | In Objective-C, there are two additional variants: |
| 5855 | |
| 5856 | foreach-statement: |
| 5857 | for ( expression in expresssion ) statement |
| 5858 | for ( declaration in expression ) statement |
| 5859 | |
| 5860 | This is inconsistent with C, because the second variant is allowed |
| 5861 | even if c99 is not enabled. |
| 5862 | |
| 5863 | The rest of the comment documents these Objective-C foreach-statement. |
| 5864 | |
| 5865 | Here is the canonical example of the first variant: |
| 5866 | for (object in array) { do something with object } |
| 5867 | we call the first expression ("object") the "object_expression" and |
| 5868 | the second expression ("array") the "collection_expression". |
| 5869 | object_expression must be an lvalue of type "id" (a generic Objective-C |
| 5870 | object) because the loop works by assigning to object_expression the |
| 5871 | various objects from the collection_expression. collection_expression |
| 5872 | must evaluate to something of type "id" which responds to the method |
| 5873 | countByEnumeratingWithState:objects:count:. |
| 5874 | |
| 5875 | The canonical example of the second variant is: |
| 5876 | for (id object in array) { do something with object } |
| 5877 | which is completely equivalent to |
| 5878 | { |
| 5879 | id object; |
| 5880 | for (object in array) { do something with object } |
| 5881 | } |
| 5882 | Note that initizializing 'object' in some way (eg, "for ((object = |
| 5883 | xxx) in array) { do something with object }") is possibly |
| 5884 | technically valid, but completely pointless as 'object' will be |
| 5885 | assigned to something else as soon as the loop starts. We should |
| 5886 | most likely reject it (TODO). |
| 5887 | |
| 5888 | The beginning of the Objective-C foreach-statement looks exactly |
| 5889 | like the beginning of the for-statement, and we can tell it is a |
| 5890 | foreach-statement only because the initial declaration or |
| 5891 | expression is terminated by 'in' instead of ';'. |
| 5892 | |
| 5893 | IF_P is used to track whether there's a (possibly labeled) if statement |
| 5894 | which is not enclosed in braces and has an else clause. This is used to |
| 5895 | implement -Wparentheses. */ |
| 5896 | |
| 5897 | static void |
| 5898 | c_parser_for_statement (c_parser *parser, bool ivdep, bool *if_p) |
| 5899 | { |
| 5900 | tree block, cond, incr, save_break, save_cont, body; |
| 5901 | /* The following are only used when parsing an ObjC foreach statement. */ |
| 5902 | tree object_expression; |
| 5903 | /* Silence the bogus uninitialized warning. */ |
| 5904 | tree collection_expression = NULL; |
| 5905 | location_t loc = c_parser_peek_token (parser)->location; |
| 5906 | location_t for_loc = c_parser_peek_token (parser)->location; |
| 5907 | bool is_foreach_statement = false; |
| 5908 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR)); |
| 5909 | token_indent_info for_tinfo |
| 5910 | = get_token_indent_info (c_parser_peek_token (parser)); |
| 5911 | c_parser_consume_token (parser); |
| 5912 | /* Open a compound statement in Objective-C as well, just in case this is |
| 5913 | as foreach expression. */ |
| 5914 | block = c_begin_compound_stmt (flag_isoc99 || c_dialect_objc ()); |
| 5915 | cond = error_mark_node; |
| 5916 | incr = error_mark_node; |
| 5917 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 5918 | { |
| 5919 | /* Parse the initialization declaration or expression. */ |
| 5920 | object_expression = error_mark_node; |
| 5921 | parser->objc_could_be_foreach_context = c_dialect_objc (); |
| 5922 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 5923 | { |
| 5924 | parser->objc_could_be_foreach_context = false; |
| 5925 | c_parser_consume_token (parser); |
| 5926 | c_finish_expr_stmt (loc, NULL_TREE); |
| 5927 | } |
| 5928 | else if (c_parser_next_tokens_start_declaration (parser)) |
| 5929 | { |
| 5930 | c_parser_declaration_or_fndef (parser, true, true, true, true, true, |
| 5931 | &object_expression, vNULL); |
| 5932 | parser->objc_could_be_foreach_context = false; |
| 5933 | |
| 5934 | if (c_parser_next_token_is_keyword (parser, RID_IN)) |
| 5935 | { |
| 5936 | c_parser_consume_token (parser); |
| 5937 | is_foreach_statement = true; |
| 5938 | if (check_for_loop_decls (for_loc, true) == NULL_TREE) |
| 5939 | c_parser_error (parser, "multiple iterating variables in fast enumeration" ); |
| 5940 | } |
| 5941 | else |
| 5942 | check_for_loop_decls (for_loc, flag_isoc99); |
| 5943 | } |
| 5944 | else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION)) |
| 5945 | { |
| 5946 | /* __extension__ can start a declaration, but is also an |
| 5947 | unary operator that can start an expression. Consume all |
| 5948 | but the last of a possible series of __extension__ to |
| 5949 | determine which. */ |
| 5950 | while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD |
| 5951 | && (c_parser_peek_2nd_token (parser)->keyword |
| 5952 | == RID_EXTENSION)) |
| 5953 | c_parser_consume_token (parser); |
| 5954 | if (c_token_starts_declaration (c_parser_peek_2nd_token (parser))) |
| 5955 | { |
| 5956 | int ext; |
| 5957 | ext = disable_extension_diagnostics (); |
| 5958 | c_parser_consume_token (parser); |
| 5959 | c_parser_declaration_or_fndef (parser, true, true, true, true, |
| 5960 | true, &object_expression, vNULL); |
| 5961 | parser->objc_could_be_foreach_context = false; |
| 5962 | |
| 5963 | restore_extension_diagnostics (ext); |
| 5964 | if (c_parser_next_token_is_keyword (parser, RID_IN)) |
| 5965 | { |
| 5966 | c_parser_consume_token (parser); |
| 5967 | is_foreach_statement = true; |
| 5968 | if (check_for_loop_decls (for_loc, true) == NULL_TREE) |
| 5969 | c_parser_error (parser, "multiple iterating variables in fast enumeration" ); |
| 5970 | } |
| 5971 | else |
| 5972 | check_for_loop_decls (for_loc, flag_isoc99); |
| 5973 | } |
| 5974 | else |
| 5975 | goto init_expr; |
| 5976 | } |
| 5977 | else |
| 5978 | { |
| 5979 | init_expr: |
| 5980 | { |
| 5981 | struct c_expr ce; |
| 5982 | tree init_expression; |
| 5983 | ce = c_parser_expression (parser); |
| 5984 | /* In theory we could forbid _Cilk_spawn here, as the spec says "only in top |
| 5985 | level statement", but it works just fine, so allow it. */ |
| 5986 | init_expression = ce.value; |
| 5987 | parser->objc_could_be_foreach_context = false; |
| 5988 | if (c_parser_next_token_is_keyword (parser, RID_IN)) |
| 5989 | { |
| 5990 | c_parser_consume_token (parser); |
| 5991 | is_foreach_statement = true; |
| 5992 | if (! lvalue_p (init_expression)) |
| 5993 | c_parser_error (parser, "invalid iterating variable in fast enumeration" ); |
| 5994 | object_expression = c_fully_fold (init_expression, false, NULL); |
| 5995 | } |
| 5996 | else |
| 5997 | { |
| 5998 | ce = convert_lvalue_to_rvalue (loc, ce, true, false); |
| 5999 | init_expression = ce.value; |
| 6000 | c_finish_expr_stmt (loc, init_expression); |
| 6001 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>" ); |
| 6002 | } |
| 6003 | } |
| 6004 | } |
| 6005 | /* Parse the loop condition. In the case of a foreach |
| 6006 | statement, there is no loop condition. */ |
| 6007 | gcc_assert (!parser->objc_could_be_foreach_context); |
| 6008 | if (!is_foreach_statement) |
| 6009 | { |
| 6010 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 6011 | { |
| 6012 | if (ivdep) |
| 6013 | { |
| 6014 | c_parser_error (parser, "missing loop condition in loop with " |
| 6015 | "%<GCC ivdep%> pragma" ); |
| 6016 | cond = error_mark_node; |
| 6017 | } |
| 6018 | else |
| 6019 | { |
| 6020 | c_parser_consume_token (parser); |
| 6021 | cond = NULL_TREE; |
| 6022 | } |
| 6023 | } |
| 6024 | else |
| 6025 | { |
| 6026 | cond = c_parser_condition (parser); |
| 6027 | if (check_no_cilk (cond, |
| 6028 | "Cilk array notation cannot be used in a condition for a for-loop" , |
| 6029 | "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop" )) |
| 6030 | cond = error_mark_node; |
| 6031 | c_parser_skip_until_found (parser, CPP_SEMICOLON, |
| 6032 | "expected %<;%>" ); |
| 6033 | } |
| 6034 | if (ivdep && cond != error_mark_node) |
| 6035 | cond = build2 (ANNOTATE_EXPR, TREE_TYPE (cond), cond, |
| 6036 | build_int_cst (integer_type_node, |
| 6037 | annot_expr_ivdep_kind)); |
| 6038 | } |
| 6039 | /* Parse the increment expression (the third expression in a |
| 6040 | for-statement). In the case of a foreach-statement, this is |
| 6041 | the expression that follows the 'in'. */ |
| 6042 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 6043 | { |
| 6044 | if (is_foreach_statement) |
| 6045 | { |
| 6046 | c_parser_error (parser, "missing collection in fast enumeration" ); |
| 6047 | collection_expression = error_mark_node; |
| 6048 | } |
| 6049 | else |
| 6050 | incr = c_process_expr_stmt (loc, NULL_TREE); |
| 6051 | } |
| 6052 | else |
| 6053 | { |
| 6054 | if (is_foreach_statement) |
| 6055 | collection_expression = c_fully_fold (c_parser_expression (parser).value, |
| 6056 | false, NULL); |
| 6057 | else |
| 6058 | { |
| 6059 | struct c_expr ce = c_parser_expression (parser); |
| 6060 | ce = convert_lvalue_to_rvalue (loc, ce, true, false); |
| 6061 | incr = c_process_expr_stmt (loc, ce.value); |
| 6062 | } |
| 6063 | } |
| 6064 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 6065 | } |
| 6066 | save_break = c_break_label; |
| 6067 | c_break_label = NULL_TREE; |
| 6068 | save_cont = c_cont_label; |
| 6069 | c_cont_label = NULL_TREE; |
| 6070 | |
| 6071 | token_indent_info body_tinfo |
| 6072 | = get_token_indent_info (c_parser_peek_token (parser)); |
| 6073 | |
| 6074 | body = c_parser_c99_block_statement (parser, if_p); |
| 6075 | |
| 6076 | if (is_foreach_statement) |
| 6077 | objc_finish_foreach_loop (loc, object_expression, collection_expression, body, c_break_label, c_cont_label); |
| 6078 | else |
| 6079 | c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true); |
| 6080 | add_stmt (c_end_compound_stmt (loc, block, flag_isoc99 || c_dialect_objc ())); |
| 6081 | c_parser_maybe_reclassify_token (parser); |
| 6082 | |
| 6083 | token_indent_info next_tinfo |
| 6084 | = get_token_indent_info (c_parser_peek_token (parser)); |
| 6085 | warn_for_misleading_indentation (for_tinfo, body_tinfo, next_tinfo); |
| 6086 | |
| 6087 | c_break_label = save_break; |
| 6088 | c_cont_label = save_cont; |
| 6089 | } |
| 6090 | |
| 6091 | /* Parse an asm statement, a GNU extension. This is a full-blown asm |
| 6092 | statement with inputs, outputs, clobbers, and volatile tag |
| 6093 | allowed. |
| 6094 | |
| 6095 | asm-statement: |
| 6096 | asm type-qualifier[opt] ( asm-argument ) ; |
| 6097 | asm type-qualifier[opt] goto ( asm-goto-argument ) ; |
| 6098 | |
| 6099 | asm-argument: |
| 6100 | asm-string-literal |
| 6101 | asm-string-literal : asm-operands[opt] |
| 6102 | asm-string-literal : asm-operands[opt] : asm-operands[opt] |
| 6103 | asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt] |
| 6104 | |
| 6105 | asm-goto-argument: |
| 6106 | asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \ |
| 6107 | : asm-goto-operands |
| 6108 | |
| 6109 | Qualifiers other than volatile are accepted in the syntax but |
| 6110 | warned for. */ |
| 6111 | |
| 6112 | static tree |
| 6113 | c_parser_asm_statement (c_parser *parser) |
| 6114 | { |
| 6115 | tree quals, str, outputs, inputs, clobbers, labels, ret; |
| 6116 | bool simple, is_goto; |
| 6117 | location_t asm_loc = c_parser_peek_token (parser)->location; |
| 6118 | int section, nsections; |
| 6119 | |
| 6120 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM)); |
| 6121 | c_parser_consume_token (parser); |
| 6122 | if (c_parser_next_token_is_keyword (parser, RID_VOLATILE)) |
| 6123 | { |
| 6124 | quals = c_parser_peek_token (parser)->value; |
| 6125 | c_parser_consume_token (parser); |
| 6126 | } |
| 6127 | else if (c_parser_next_token_is_keyword (parser, RID_CONST) |
| 6128 | || c_parser_next_token_is_keyword (parser, RID_RESTRICT)) |
| 6129 | { |
| 6130 | warning_at (c_parser_peek_token (parser)->location, |
| 6131 | 0, |
| 6132 | "%E qualifier ignored on asm" , |
| 6133 | c_parser_peek_token (parser)->value); |
| 6134 | quals = NULL_TREE; |
| 6135 | c_parser_consume_token (parser); |
| 6136 | } |
| 6137 | else |
| 6138 | quals = NULL_TREE; |
| 6139 | |
| 6140 | is_goto = false; |
| 6141 | if (c_parser_next_token_is_keyword (parser, RID_GOTO)) |
| 6142 | { |
| 6143 | c_parser_consume_token (parser); |
| 6144 | is_goto = true; |
| 6145 | } |
| 6146 | |
| 6147 | /* ??? Follow the C++ parser rather than using the |
| 6148 | lex_untranslated_string kludge. */ |
| 6149 | parser->lex_untranslated_string = true; |
| 6150 | ret = NULL; |
| 6151 | |
| 6152 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 6153 | goto error; |
| 6154 | |
| 6155 | str = c_parser_asm_string_literal (parser); |
| 6156 | if (str == NULL_TREE) |
| 6157 | goto error_close_paren; |
| 6158 | |
| 6159 | simple = true; |
| 6160 | outputs = NULL_TREE; |
| 6161 | inputs = NULL_TREE; |
| 6162 | clobbers = NULL_TREE; |
| 6163 | labels = NULL_TREE; |
| 6164 | |
| 6165 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto) |
| 6166 | goto done_asm; |
| 6167 | |
| 6168 | /* Parse each colon-delimited section of operands. */ |
| 6169 | nsections = 3 + is_goto; |
| 6170 | for (section = 0; section < nsections; ++section) |
| 6171 | { |
| 6172 | if (!c_parser_require (parser, CPP_COLON, |
| 6173 | is_goto |
| 6174 | ? G_("expected %<:%>" ) |
| 6175 | : G_("expected %<:%> or %<)%>" ))) |
| 6176 | goto error_close_paren; |
| 6177 | |
| 6178 | /* Once past any colon, we're no longer a simple asm. */ |
| 6179 | simple = false; |
| 6180 | |
| 6181 | if ((!c_parser_next_token_is (parser, CPP_COLON) |
| 6182 | && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 6183 | || section == 3) |
| 6184 | switch (section) |
| 6185 | { |
| 6186 | case 0: |
| 6187 | /* For asm goto, we don't allow output operands, but reserve |
| 6188 | the slot for a future extension that does allow them. */ |
| 6189 | if (!is_goto) |
| 6190 | outputs = c_parser_asm_operands (parser); |
| 6191 | break; |
| 6192 | case 1: |
| 6193 | inputs = c_parser_asm_operands (parser); |
| 6194 | break; |
| 6195 | case 2: |
| 6196 | clobbers = c_parser_asm_clobbers (parser); |
| 6197 | break; |
| 6198 | case 3: |
| 6199 | labels = c_parser_asm_goto_operands (parser); |
| 6200 | break; |
| 6201 | default: |
| 6202 | gcc_unreachable (); |
| 6203 | } |
| 6204 | |
| 6205 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto) |
| 6206 | goto done_asm; |
| 6207 | } |
| 6208 | |
| 6209 | done_asm: |
| 6210 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>" )) |
| 6211 | { |
| 6212 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 6213 | goto error; |
| 6214 | } |
| 6215 | |
| 6216 | if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>" )) |
| 6217 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 6218 | |
| 6219 | ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs, |
| 6220 | clobbers, labels, simple)); |
| 6221 | |
| 6222 | error: |
| 6223 | parser->lex_untranslated_string = false; |
| 6224 | return ret; |
| 6225 | |
| 6226 | error_close_paren: |
| 6227 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 6228 | goto error; |
| 6229 | } |
| 6230 | |
| 6231 | /* Parse asm operands, a GNU extension. |
| 6232 | |
| 6233 | asm-operands: |
| 6234 | asm-operand |
| 6235 | asm-operands , asm-operand |
| 6236 | |
| 6237 | asm-operand: |
| 6238 | asm-string-literal ( expression ) |
| 6239 | [ identifier ] asm-string-literal ( expression ) |
| 6240 | */ |
| 6241 | |
| 6242 | static tree |
| 6243 | c_parser_asm_operands (c_parser *parser) |
| 6244 | { |
| 6245 | tree list = NULL_TREE; |
| 6246 | while (true) |
| 6247 | { |
| 6248 | tree name, str; |
| 6249 | struct c_expr expr; |
| 6250 | if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) |
| 6251 | { |
| 6252 | c_parser_consume_token (parser); |
| 6253 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 6254 | { |
| 6255 | tree id = c_parser_peek_token (parser)->value; |
| 6256 | c_parser_consume_token (parser); |
| 6257 | name = build_string (IDENTIFIER_LENGTH (id), |
| 6258 | IDENTIFIER_POINTER (id)); |
| 6259 | } |
| 6260 | else |
| 6261 | { |
| 6262 | c_parser_error (parser, "expected identifier" ); |
| 6263 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); |
| 6264 | return NULL_TREE; |
| 6265 | } |
| 6266 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, |
| 6267 | "expected %<]%>" ); |
| 6268 | } |
| 6269 | else |
| 6270 | name = NULL_TREE; |
| 6271 | str = c_parser_asm_string_literal (parser); |
| 6272 | if (str == NULL_TREE) |
| 6273 | return NULL_TREE; |
| 6274 | parser->lex_untranslated_string = false; |
| 6275 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 6276 | { |
| 6277 | parser->lex_untranslated_string = true; |
| 6278 | return NULL_TREE; |
| 6279 | } |
| 6280 | expr = c_parser_expression (parser); |
| 6281 | mark_exp_read (expr.value); |
| 6282 | parser->lex_untranslated_string = true; |
| 6283 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>" )) |
| 6284 | { |
| 6285 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 6286 | return NULL_TREE; |
| 6287 | } |
| 6288 | list = chainon (list, build_tree_list (build_tree_list (name, str), |
| 6289 | expr.value)); |
| 6290 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 6291 | c_parser_consume_token (parser); |
| 6292 | else |
| 6293 | break; |
| 6294 | } |
| 6295 | return list; |
| 6296 | } |
| 6297 | |
| 6298 | /* Parse asm clobbers, a GNU extension. |
| 6299 | |
| 6300 | asm-clobbers: |
| 6301 | asm-string-literal |
| 6302 | asm-clobbers , asm-string-literal |
| 6303 | */ |
| 6304 | |
| 6305 | static tree |
| 6306 | c_parser_asm_clobbers (c_parser *parser) |
| 6307 | { |
| 6308 | tree list = NULL_TREE; |
| 6309 | while (true) |
| 6310 | { |
| 6311 | tree str = c_parser_asm_string_literal (parser); |
| 6312 | if (str) |
| 6313 | list = tree_cons (NULL_TREE, str, list); |
| 6314 | else |
| 6315 | return NULL_TREE; |
| 6316 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 6317 | c_parser_consume_token (parser); |
| 6318 | else |
| 6319 | break; |
| 6320 | } |
| 6321 | return list; |
| 6322 | } |
| 6323 | |
| 6324 | /* Parse asm goto labels, a GNU extension. |
| 6325 | |
| 6326 | asm-goto-operands: |
| 6327 | identifier |
| 6328 | asm-goto-operands , identifier |
| 6329 | */ |
| 6330 | |
| 6331 | static tree |
| 6332 | c_parser_asm_goto_operands (c_parser *parser) |
| 6333 | { |
| 6334 | tree list = NULL_TREE; |
| 6335 | while (true) |
| 6336 | { |
| 6337 | tree name, label; |
| 6338 | |
| 6339 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 6340 | { |
| 6341 | c_token *tok = c_parser_peek_token (parser); |
| 6342 | name = tok->value; |
| 6343 | label = lookup_label_for_goto (tok->location, name); |
| 6344 | c_parser_consume_token (parser); |
| 6345 | TREE_USED (label) = 1; |
| 6346 | } |
| 6347 | else |
| 6348 | { |
| 6349 | c_parser_error (parser, "expected identifier" ); |
| 6350 | return NULL_TREE; |
| 6351 | } |
| 6352 | |
| 6353 | name = build_string (IDENTIFIER_LENGTH (name), |
| 6354 | IDENTIFIER_POINTER (name)); |
| 6355 | list = tree_cons (name, label, list); |
| 6356 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 6357 | c_parser_consume_token (parser); |
| 6358 | else |
| 6359 | return nreverse (list); |
| 6360 | } |
| 6361 | } |
| 6362 | |
| 6363 | /* Parse an expression other than a compound expression; that is, an |
| 6364 | assignment expression (C90 6.3.16, C99 6.5.16, C11 6.5.16). If |
| 6365 | AFTER is not NULL then it is an Objective-C message expression which |
| 6366 | is the primary-expression starting the expression as an initializer. |
| 6367 | |
| 6368 | assignment-expression: |
| 6369 | conditional-expression |
| 6370 | unary-expression assignment-operator assignment-expression |
| 6371 | |
| 6372 | assignment-operator: one of |
| 6373 | = *= /= %= += -= <<= >>= &= ^= |= |
| 6374 | |
| 6375 | In GNU C we accept any conditional expression on the LHS and |
| 6376 | diagnose the invalid lvalue rather than producing a syntax |
| 6377 | error. */ |
| 6378 | |
| 6379 | static struct c_expr |
| 6380 | c_parser_expr_no_commas (c_parser *parser, struct c_expr *after, |
| 6381 | tree omp_atomic_lhs) |
| 6382 | { |
| 6383 | struct c_expr lhs, rhs, ret; |
| 6384 | enum tree_code code; |
| 6385 | location_t op_location, exp_location; |
| 6386 | gcc_assert (!after || c_dialect_objc ()); |
| 6387 | lhs = c_parser_conditional_expression (parser, after, omp_atomic_lhs); |
| 6388 | op_location = c_parser_peek_token (parser)->location; |
| 6389 | switch (c_parser_peek_token (parser)->type) |
| 6390 | { |
| 6391 | case CPP_EQ: |
| 6392 | code = NOP_EXPR; |
| 6393 | break; |
| 6394 | case CPP_MULT_EQ: |
| 6395 | code = MULT_EXPR; |
| 6396 | break; |
| 6397 | case CPP_DIV_EQ: |
| 6398 | code = TRUNC_DIV_EXPR; |
| 6399 | break; |
| 6400 | case CPP_MOD_EQ: |
| 6401 | code = TRUNC_MOD_EXPR; |
| 6402 | break; |
| 6403 | case CPP_PLUS_EQ: |
| 6404 | code = PLUS_EXPR; |
| 6405 | break; |
| 6406 | case CPP_MINUS_EQ: |
| 6407 | code = MINUS_EXPR; |
| 6408 | break; |
| 6409 | case CPP_LSHIFT_EQ: |
| 6410 | code = LSHIFT_EXPR; |
| 6411 | break; |
| 6412 | case CPP_RSHIFT_EQ: |
| 6413 | code = RSHIFT_EXPR; |
| 6414 | break; |
| 6415 | case CPP_AND_EQ: |
| 6416 | code = BIT_AND_EXPR; |
| 6417 | break; |
| 6418 | case CPP_XOR_EQ: |
| 6419 | code = BIT_XOR_EXPR; |
| 6420 | break; |
| 6421 | case CPP_OR_EQ: |
| 6422 | code = BIT_IOR_EXPR; |
| 6423 | break; |
| 6424 | default: |
| 6425 | return lhs; |
| 6426 | } |
| 6427 | c_parser_consume_token (parser); |
| 6428 | exp_location = c_parser_peek_token (parser)->location; |
| 6429 | rhs = c_parser_expr_no_commas (parser, NULL); |
| 6430 | rhs = convert_lvalue_to_rvalue (exp_location, rhs, true, true); |
| 6431 | |
| 6432 | ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type, |
| 6433 | code, exp_location, rhs.value, |
| 6434 | rhs.original_type); |
| 6435 | set_c_expr_source_range (&ret, lhs.get_start (), rhs.get_finish ()); |
| 6436 | if (code == NOP_EXPR) |
| 6437 | ret.original_code = MODIFY_EXPR; |
| 6438 | else |
| 6439 | { |
| 6440 | TREE_NO_WARNING (ret.value) = 1; |
| 6441 | ret.original_code = ERROR_MARK; |
| 6442 | } |
| 6443 | ret.original_type = NULL; |
| 6444 | return ret; |
| 6445 | } |
| 6446 | |
| 6447 | /* Parse a conditional expression (C90 6.3.15, C99 6.5.15, C11 6.5.15). If |
| 6448 | AFTER is not NULL then it is an Objective-C message expression which is |
| 6449 | the primary-expression starting the expression as an initializer. |
| 6450 | |
| 6451 | conditional-expression: |
| 6452 | logical-OR-expression |
| 6453 | logical-OR-expression ? expression : conditional-expression |
| 6454 | |
| 6455 | GNU extensions: |
| 6456 | |
| 6457 | conditional-expression: |
| 6458 | logical-OR-expression ? : conditional-expression |
| 6459 | */ |
| 6460 | |
| 6461 | static struct c_expr |
| 6462 | c_parser_conditional_expression (c_parser *parser, struct c_expr *after, |
| 6463 | tree omp_atomic_lhs) |
| 6464 | { |
| 6465 | struct c_expr cond, exp1, exp2, ret; |
| 6466 | location_t start, cond_loc, colon_loc, middle_loc; |
| 6467 | |
| 6468 | gcc_assert (!after || c_dialect_objc ()); |
| 6469 | |
| 6470 | cond = c_parser_binary_expression (parser, after, omp_atomic_lhs); |
| 6471 | |
| 6472 | if (c_parser_next_token_is_not (parser, CPP_QUERY)) |
| 6473 | return cond; |
| 6474 | if (cond.value != error_mark_node) |
| 6475 | start = cond.get_start (); |
| 6476 | else |
| 6477 | start = UNKNOWN_LOCATION; |
| 6478 | cond_loc = c_parser_peek_token (parser)->location; |
| 6479 | cond = convert_lvalue_to_rvalue (cond_loc, cond, true, true); |
| 6480 | c_parser_consume_token (parser); |
| 6481 | if (c_parser_next_token_is (parser, CPP_COLON)) |
| 6482 | { |
| 6483 | tree eptype = NULL_TREE; |
| 6484 | |
| 6485 | middle_loc = c_parser_peek_token (parser)->location; |
| 6486 | pedwarn (middle_loc, OPT_Wpedantic, |
| 6487 | "ISO C forbids omitting the middle term of a ?: expression" ); |
| 6488 | if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR) |
| 6489 | { |
| 6490 | eptype = TREE_TYPE (cond.value); |
| 6491 | cond.value = TREE_OPERAND (cond.value, 0); |
| 6492 | } |
| 6493 | tree e = cond.value; |
| 6494 | while (TREE_CODE (e) == COMPOUND_EXPR) |
| 6495 | e = TREE_OPERAND (e, 1); |
| 6496 | warn_for_omitted_condop (middle_loc, e); |
| 6497 | /* Make sure first operand is calculated only once. */ |
| 6498 | exp1.value = c_save_expr (default_conversion (cond.value)); |
| 6499 | if (eptype) |
| 6500 | exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value); |
| 6501 | exp1.original_type = NULL; |
| 6502 | cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value); |
| 6503 | c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node; |
| 6504 | } |
| 6505 | else |
| 6506 | { |
| 6507 | cond.value |
| 6508 | = c_objc_common_truthvalue_conversion |
| 6509 | (cond_loc, default_conversion (cond.value)); |
| 6510 | c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node; |
| 6511 | exp1 = c_parser_expression_conv (parser); |
| 6512 | mark_exp_read (exp1.value); |
| 6513 | c_inhibit_evaluation_warnings += |
| 6514 | ((cond.value == truthvalue_true_node) |
| 6515 | - (cond.value == truthvalue_false_node)); |
| 6516 | } |
| 6517 | |
| 6518 | colon_loc = c_parser_peek_token (parser)->location; |
| 6519 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>" )) |
| 6520 | { |
| 6521 | c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node; |
| 6522 | ret.value = error_mark_node; |
| 6523 | ret.original_code = ERROR_MARK; |
| 6524 | ret.original_type = NULL; |
| 6525 | return ret; |
| 6526 | } |
| 6527 | { |
| 6528 | location_t exp2_loc = c_parser_peek_token (parser)->location; |
| 6529 | exp2 = c_parser_conditional_expression (parser, NULL, NULL_TREE); |
| 6530 | exp2 = convert_lvalue_to_rvalue (exp2_loc, exp2, true, true); |
| 6531 | } |
| 6532 | c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node; |
| 6533 | ret.value = build_conditional_expr (colon_loc, cond.value, |
| 6534 | cond.original_code == C_MAYBE_CONST_EXPR, |
| 6535 | exp1.value, exp1.original_type, |
| 6536 | exp2.value, exp2.original_type); |
| 6537 | ret.original_code = ERROR_MARK; |
| 6538 | if (exp1.value == error_mark_node || exp2.value == error_mark_node) |
| 6539 | ret.original_type = NULL; |
| 6540 | else |
| 6541 | { |
| 6542 | tree t1, t2; |
| 6543 | |
| 6544 | /* If both sides are enum type, the default conversion will have |
| 6545 | made the type of the result be an integer type. We want to |
| 6546 | remember the enum types we started with. */ |
| 6547 | t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value); |
| 6548 | t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value); |
| 6549 | ret.original_type = ((t1 != error_mark_node |
| 6550 | && t2 != error_mark_node |
| 6551 | && (TYPE_MAIN_VARIANT (t1) |
| 6552 | == TYPE_MAIN_VARIANT (t2))) |
| 6553 | ? t1 |
| 6554 | : NULL); |
| 6555 | } |
| 6556 | set_c_expr_source_range (&ret, start, exp2.get_finish ()); |
| 6557 | return ret; |
| 6558 | } |
| 6559 | |
| 6560 | /* Parse a binary expression; that is, a logical-OR-expression (C90 |
| 6561 | 6.3.5-6.3.14, C99 6.5.5-6.5.14, C11 6.5.5-6.5.14). If AFTER is not |
| 6562 | NULL then it is an Objective-C message expression which is the |
| 6563 | primary-expression starting the expression as an initializer. |
| 6564 | |
| 6565 | OMP_ATOMIC_LHS is NULL, unless parsing OpenMP #pragma omp atomic, |
| 6566 | when it should be the unfolded lhs. In a valid OpenMP source, |
| 6567 | one of the operands of the toplevel binary expression must be equal |
| 6568 | to it. In that case, just return a build2 created binary operation |
| 6569 | rather than result of parser_build_binary_op. |
| 6570 | |
| 6571 | multiplicative-expression: |
| 6572 | cast-expression |
| 6573 | multiplicative-expression * cast-expression |
| 6574 | multiplicative-expression / cast-expression |
| 6575 | multiplicative-expression % cast-expression |
| 6576 | |
| 6577 | additive-expression: |
| 6578 | multiplicative-expression |
| 6579 | additive-expression + multiplicative-expression |
| 6580 | additive-expression - multiplicative-expression |
| 6581 | |
| 6582 | shift-expression: |
| 6583 | additive-expression |
| 6584 | shift-expression << additive-expression |
| 6585 | shift-expression >> additive-expression |
| 6586 | |
| 6587 | relational-expression: |
| 6588 | shift-expression |
| 6589 | relational-expression < shift-expression |
| 6590 | relational-expression > shift-expression |
| 6591 | relational-expression <= shift-expression |
| 6592 | relational-expression >= shift-expression |
| 6593 | |
| 6594 | equality-expression: |
| 6595 | relational-expression |
| 6596 | equality-expression == relational-expression |
| 6597 | equality-expression != relational-expression |
| 6598 | |
| 6599 | AND-expression: |
| 6600 | equality-expression |
| 6601 | AND-expression & equality-expression |
| 6602 | |
| 6603 | exclusive-OR-expression: |
| 6604 | AND-expression |
| 6605 | exclusive-OR-expression ^ AND-expression |
| 6606 | |
| 6607 | inclusive-OR-expression: |
| 6608 | exclusive-OR-expression |
| 6609 | inclusive-OR-expression | exclusive-OR-expression |
| 6610 | |
| 6611 | logical-AND-expression: |
| 6612 | inclusive-OR-expression |
| 6613 | logical-AND-expression && inclusive-OR-expression |
| 6614 | |
| 6615 | logical-OR-expression: |
| 6616 | logical-AND-expression |
| 6617 | logical-OR-expression || logical-AND-expression |
| 6618 | */ |
| 6619 | |
| 6620 | static struct c_expr |
| 6621 | c_parser_binary_expression (c_parser *parser, struct c_expr *after, |
| 6622 | tree omp_atomic_lhs) |
| 6623 | { |
| 6624 | /* A binary expression is parsed using operator-precedence parsing, |
| 6625 | with the operands being cast expressions. All the binary |
| 6626 | operators are left-associative. Thus a binary expression is of |
| 6627 | form: |
| 6628 | |
| 6629 | E0 op1 E1 op2 E2 ... |
| 6630 | |
| 6631 | which we represent on a stack. On the stack, the precedence |
| 6632 | levels are strictly increasing. When a new operator is |
| 6633 | encountered of higher precedence than that at the top of the |
| 6634 | stack, it is pushed; its LHS is the top expression, and its RHS |
| 6635 | is everything parsed until it is popped. When a new operator is |
| 6636 | encountered with precedence less than or equal to that at the top |
| 6637 | of the stack, triples E[i-1] op[i] E[i] are popped and replaced |
| 6638 | by the result of the operation until the operator at the top of |
| 6639 | the stack has lower precedence than the new operator or there is |
| 6640 | only one element on the stack; then the top expression is the LHS |
| 6641 | of the new operator. In the case of logical AND and OR |
| 6642 | expressions, we also need to adjust c_inhibit_evaluation_warnings |
| 6643 | as appropriate when the operators are pushed and popped. */ |
| 6644 | |
| 6645 | struct { |
| 6646 | /* The expression at this stack level. */ |
| 6647 | struct c_expr expr; |
| 6648 | /* The precedence of the operator on its left, PREC_NONE at the |
| 6649 | bottom of the stack. */ |
| 6650 | enum c_parser_prec prec; |
| 6651 | /* The operation on its left. */ |
| 6652 | enum tree_code op; |
| 6653 | /* The source location of this operation. */ |
| 6654 | location_t loc; |
| 6655 | } stack[NUM_PRECS]; |
| 6656 | int sp; |
| 6657 | /* Location of the binary operator. */ |
| 6658 | location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */ |
| 6659 | #define POP \ |
| 6660 | do { \ |
| 6661 | switch (stack[sp].op) \ |
| 6662 | { \ |
| 6663 | case TRUTH_ANDIF_EXPR: \ |
| 6664 | c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \ |
| 6665 | == truthvalue_false_node); \ |
| 6666 | break; \ |
| 6667 | case TRUTH_ORIF_EXPR: \ |
| 6668 | c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \ |
| 6669 | == truthvalue_true_node); \ |
| 6670 | break; \ |
| 6671 | default: \ |
| 6672 | break; \ |
| 6673 | } \ |
| 6674 | stack[sp - 1].expr \ |
| 6675 | = convert_lvalue_to_rvalue (stack[sp - 1].loc, \ |
| 6676 | stack[sp - 1].expr, true, true); \ |
| 6677 | stack[sp].expr \ |
| 6678 | = convert_lvalue_to_rvalue (stack[sp].loc, \ |
| 6679 | stack[sp].expr, true, true); \ |
| 6680 | if (__builtin_expect (omp_atomic_lhs != NULL_TREE, 0) && sp == 1 \ |
| 6681 | && c_parser_peek_token (parser)->type == CPP_SEMICOLON \ |
| 6682 | && ((1 << stack[sp].prec) \ |
| 6683 | & ((1 << PREC_BITOR) | (1 << PREC_BITXOR) | (1 << PREC_BITAND) \ |
| 6684 | | (1 << PREC_SHIFT) | (1 << PREC_ADD) | (1 << PREC_MULT))) \ |
| 6685 | && stack[sp].op != TRUNC_MOD_EXPR \ |
| 6686 | && stack[0].expr.value != error_mark_node \ |
| 6687 | && stack[1].expr.value != error_mark_node \ |
| 6688 | && (c_tree_equal (stack[0].expr.value, omp_atomic_lhs) \ |
| 6689 | || c_tree_equal (stack[1].expr.value, omp_atomic_lhs))) \ |
| 6690 | stack[0].expr.value \ |
| 6691 | = build2 (stack[1].op, TREE_TYPE (stack[0].expr.value), \ |
| 6692 | stack[0].expr.value, stack[1].expr.value); \ |
| 6693 | else \ |
| 6694 | stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \ |
| 6695 | stack[sp].op, \ |
| 6696 | stack[sp - 1].expr, \ |
| 6697 | stack[sp].expr); \ |
| 6698 | sp--; \ |
| 6699 | } while (0) |
| 6700 | gcc_assert (!after || c_dialect_objc ()); |
| 6701 | stack[0].loc = c_parser_peek_token (parser)->location; |
| 6702 | stack[0].expr = c_parser_cast_expression (parser, after); |
| 6703 | stack[0].prec = PREC_NONE; |
| 6704 | sp = 0; |
| 6705 | while (true) |
| 6706 | { |
| 6707 | enum c_parser_prec oprec; |
| 6708 | enum tree_code ocode; |
| 6709 | source_range src_range; |
| 6710 | if (parser->error) |
| 6711 | goto out; |
| 6712 | switch (c_parser_peek_token (parser)->type) |
| 6713 | { |
| 6714 | case CPP_MULT: |
| 6715 | oprec = PREC_MULT; |
| 6716 | ocode = MULT_EXPR; |
| 6717 | break; |
| 6718 | case CPP_DIV: |
| 6719 | oprec = PREC_MULT; |
| 6720 | ocode = TRUNC_DIV_EXPR; |
| 6721 | break; |
| 6722 | case CPP_MOD: |
| 6723 | oprec = PREC_MULT; |
| 6724 | ocode = TRUNC_MOD_EXPR; |
| 6725 | break; |
| 6726 | case CPP_PLUS: |
| 6727 | oprec = PREC_ADD; |
| 6728 | ocode = PLUS_EXPR; |
| 6729 | break; |
| 6730 | case CPP_MINUS: |
| 6731 | oprec = PREC_ADD; |
| 6732 | ocode = MINUS_EXPR; |
| 6733 | break; |
| 6734 | case CPP_LSHIFT: |
| 6735 | oprec = PREC_SHIFT; |
| 6736 | ocode = LSHIFT_EXPR; |
| 6737 | break; |
| 6738 | case CPP_RSHIFT: |
| 6739 | oprec = PREC_SHIFT; |
| 6740 | ocode = RSHIFT_EXPR; |
| 6741 | break; |
| 6742 | case CPP_LESS: |
| 6743 | oprec = PREC_REL; |
| 6744 | ocode = LT_EXPR; |
| 6745 | break; |
| 6746 | case CPP_GREATER: |
| 6747 | oprec = PREC_REL; |
| 6748 | ocode = GT_EXPR; |
| 6749 | break; |
| 6750 | case CPP_LESS_EQ: |
| 6751 | oprec = PREC_REL; |
| 6752 | ocode = LE_EXPR; |
| 6753 | break; |
| 6754 | case CPP_GREATER_EQ: |
| 6755 | oprec = PREC_REL; |
| 6756 | ocode = GE_EXPR; |
| 6757 | break; |
| 6758 | case CPP_EQ_EQ: |
| 6759 | oprec = PREC_EQ; |
| 6760 | ocode = EQ_EXPR; |
| 6761 | break; |
| 6762 | case CPP_NOT_EQ: |
| 6763 | oprec = PREC_EQ; |
| 6764 | ocode = NE_EXPR; |
| 6765 | break; |
| 6766 | case CPP_AND: |
| 6767 | oprec = PREC_BITAND; |
| 6768 | ocode = BIT_AND_EXPR; |
| 6769 | break; |
| 6770 | case CPP_XOR: |
| 6771 | oprec = PREC_BITXOR; |
| 6772 | ocode = BIT_XOR_EXPR; |
| 6773 | break; |
| 6774 | case CPP_OR: |
| 6775 | oprec = PREC_BITOR; |
| 6776 | ocode = BIT_IOR_EXPR; |
| 6777 | break; |
| 6778 | case CPP_AND_AND: |
| 6779 | oprec = PREC_LOGAND; |
| 6780 | ocode = TRUTH_ANDIF_EXPR; |
| 6781 | break; |
| 6782 | case CPP_OR_OR: |
| 6783 | oprec = PREC_LOGOR; |
| 6784 | ocode = TRUTH_ORIF_EXPR; |
| 6785 | break; |
| 6786 | default: |
| 6787 | /* Not a binary operator, so end of the binary |
| 6788 | expression. */ |
| 6789 | goto out; |
| 6790 | } |
| 6791 | binary_loc = c_parser_peek_token (parser)->location; |
| 6792 | while (oprec <= stack[sp].prec) |
| 6793 | POP; |
| 6794 | c_parser_consume_token (parser); |
| 6795 | switch (ocode) |
| 6796 | { |
| 6797 | case TRUTH_ANDIF_EXPR: |
| 6798 | src_range = stack[sp].expr.src_range; |
| 6799 | stack[sp].expr |
| 6800 | = convert_lvalue_to_rvalue (stack[sp].loc, |
| 6801 | stack[sp].expr, true, true); |
| 6802 | stack[sp].expr.value = c_objc_common_truthvalue_conversion |
| 6803 | (stack[sp].loc, default_conversion (stack[sp].expr.value)); |
| 6804 | c_inhibit_evaluation_warnings += (stack[sp].expr.value |
| 6805 | == truthvalue_false_node); |
| 6806 | set_c_expr_source_range (&stack[sp].expr, src_range); |
| 6807 | break; |
| 6808 | case TRUTH_ORIF_EXPR: |
| 6809 | src_range = stack[sp].expr.src_range; |
| 6810 | stack[sp].expr |
| 6811 | = convert_lvalue_to_rvalue (stack[sp].loc, |
| 6812 | stack[sp].expr, true, true); |
| 6813 | stack[sp].expr.value = c_objc_common_truthvalue_conversion |
| 6814 | (stack[sp].loc, default_conversion (stack[sp].expr.value)); |
| 6815 | c_inhibit_evaluation_warnings += (stack[sp].expr.value |
| 6816 | == truthvalue_true_node); |
| 6817 | set_c_expr_source_range (&stack[sp].expr, src_range); |
| 6818 | break; |
| 6819 | default: |
| 6820 | break; |
| 6821 | } |
| 6822 | sp++; |
| 6823 | stack[sp].loc = binary_loc; |
| 6824 | stack[sp].expr = c_parser_cast_expression (parser, NULL); |
| 6825 | stack[sp].prec = oprec; |
| 6826 | stack[sp].op = ocode; |
| 6827 | } |
| 6828 | out: |
| 6829 | while (sp > 0) |
| 6830 | POP; |
| 6831 | return stack[0].expr; |
| 6832 | #undef POP |
| 6833 | } |
| 6834 | |
| 6835 | /* Parse a cast expression (C90 6.3.4, C99 6.5.4, C11 6.5.4). If AFTER |
| 6836 | is not NULL then it is an Objective-C message expression which is the |
| 6837 | primary-expression starting the expression as an initializer. |
| 6838 | |
| 6839 | cast-expression: |
| 6840 | unary-expression |
| 6841 | ( type-name ) unary-expression |
| 6842 | */ |
| 6843 | |
| 6844 | static struct c_expr |
| 6845 | c_parser_cast_expression (c_parser *parser, struct c_expr *after) |
| 6846 | { |
| 6847 | location_t cast_loc = c_parser_peek_token (parser)->location; |
| 6848 | gcc_assert (!after || c_dialect_objc ()); |
| 6849 | if (after) |
| 6850 | return c_parser_postfix_expression_after_primary (parser, |
| 6851 | cast_loc, *after); |
| 6852 | /* If the expression begins with a parenthesized type name, it may |
| 6853 | be either a cast or a compound literal; we need to see whether |
| 6854 | the next character is '{' to tell the difference. If not, it is |
| 6855 | an unary expression. Full detection of unknown typenames here |
| 6856 | would require a 3-token lookahead. */ |
| 6857 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) |
| 6858 | && c_token_starts_typename (c_parser_peek_2nd_token (parser))) |
| 6859 | { |
| 6860 | struct c_type_name *type_name; |
| 6861 | struct c_expr ret; |
| 6862 | struct c_expr expr; |
| 6863 | c_parser_consume_token (parser); |
| 6864 | type_name = c_parser_type_name (parser); |
| 6865 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 6866 | if (type_name == NULL) |
| 6867 | { |
| 6868 | ret.value = error_mark_node; |
| 6869 | ret.original_code = ERROR_MARK; |
| 6870 | ret.original_type = NULL; |
| 6871 | return ret; |
| 6872 | } |
| 6873 | |
| 6874 | /* Save casted types in the function's used types hash table. */ |
| 6875 | used_types_insert (type_name->specs->type); |
| 6876 | |
| 6877 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 6878 | return c_parser_postfix_expression_after_paren_type (parser, type_name, |
| 6879 | cast_loc); |
| 6880 | { |
| 6881 | location_t expr_loc = c_parser_peek_token (parser)->location; |
| 6882 | expr = c_parser_cast_expression (parser, NULL); |
| 6883 | expr = convert_lvalue_to_rvalue (expr_loc, expr, true, true); |
| 6884 | } |
| 6885 | ret.value = c_cast_expr (cast_loc, type_name, expr.value); |
| 6886 | if (ret.value && expr.value) |
| 6887 | set_c_expr_source_range (&ret, cast_loc, expr.get_finish ()); |
| 6888 | ret.original_code = ERROR_MARK; |
| 6889 | ret.original_type = NULL; |
| 6890 | return ret; |
| 6891 | } |
| 6892 | else |
| 6893 | return c_parser_unary_expression (parser); |
| 6894 | } |
| 6895 | |
| 6896 | /* Parse an unary expression (C90 6.3.3, C99 6.5.3, C11 6.5.3). |
| 6897 | |
| 6898 | unary-expression: |
| 6899 | postfix-expression |
| 6900 | ++ unary-expression |
| 6901 | -- unary-expression |
| 6902 | unary-operator cast-expression |
| 6903 | sizeof unary-expression |
| 6904 | sizeof ( type-name ) |
| 6905 | |
| 6906 | unary-operator: one of |
| 6907 | & * + - ~ ! |
| 6908 | |
| 6909 | GNU extensions: |
| 6910 | |
| 6911 | unary-expression: |
| 6912 | __alignof__ unary-expression |
| 6913 | __alignof__ ( type-name ) |
| 6914 | && identifier |
| 6915 | |
| 6916 | (C11 permits _Alignof with type names only.) |
| 6917 | |
| 6918 | unary-operator: one of |
| 6919 | __extension__ __real__ __imag__ |
| 6920 | |
| 6921 | Transactional Memory: |
| 6922 | |
| 6923 | unary-expression: |
| 6924 | transaction-expression |
| 6925 | |
| 6926 | In addition, the GNU syntax treats ++ and -- as unary operators, so |
| 6927 | they may be applied to cast expressions with errors for non-lvalues |
| 6928 | given later. */ |
| 6929 | |
| 6930 | static struct c_expr |
| 6931 | c_parser_unary_expression (c_parser *parser) |
| 6932 | { |
| 6933 | int ext; |
| 6934 | struct c_expr ret, op; |
| 6935 | location_t op_loc = c_parser_peek_token (parser)->location; |
| 6936 | location_t exp_loc; |
| 6937 | location_t finish; |
| 6938 | ret.original_code = ERROR_MARK; |
| 6939 | ret.original_type = NULL; |
| 6940 | switch (c_parser_peek_token (parser)->type) |
| 6941 | { |
| 6942 | case CPP_PLUS_PLUS: |
| 6943 | c_parser_consume_token (parser); |
| 6944 | exp_loc = c_parser_peek_token (parser)->location; |
| 6945 | op = c_parser_cast_expression (parser, NULL); |
| 6946 | |
| 6947 | /* If there is array notations in op, we expand them. */ |
| 6948 | if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF) |
| 6949 | return fix_array_notation_expr (exp_loc, PREINCREMENT_EXPR, op); |
| 6950 | else |
| 6951 | { |
| 6952 | op = default_function_array_read_conversion (exp_loc, op); |
| 6953 | return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op); |
| 6954 | } |
| 6955 | case CPP_MINUS_MINUS: |
| 6956 | c_parser_consume_token (parser); |
| 6957 | exp_loc = c_parser_peek_token (parser)->location; |
| 6958 | op = c_parser_cast_expression (parser, NULL); |
| 6959 | |
| 6960 | /* If there is array notations in op, we expand them. */ |
| 6961 | if (flag_cilkplus && TREE_CODE (op.value) == ARRAY_NOTATION_REF) |
| 6962 | return fix_array_notation_expr (exp_loc, PREDECREMENT_EXPR, op); |
| 6963 | else |
| 6964 | { |
| 6965 | op = default_function_array_read_conversion (exp_loc, op); |
| 6966 | return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op); |
| 6967 | } |
| 6968 | case CPP_AND: |
| 6969 | c_parser_consume_token (parser); |
| 6970 | op = c_parser_cast_expression (parser, NULL); |
| 6971 | mark_exp_read (op.value); |
| 6972 | return parser_build_unary_op (op_loc, ADDR_EXPR, op); |
| 6973 | case CPP_MULT: |
| 6974 | { |
| 6975 | c_parser_consume_token (parser); |
| 6976 | exp_loc = c_parser_peek_token (parser)->location; |
| 6977 | op = c_parser_cast_expression (parser, NULL); |
| 6978 | finish = op.get_finish (); |
| 6979 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
| 6980 | location_t combined_loc = make_location (op_loc, op_loc, finish); |
| 6981 | ret.value = build_indirect_ref (combined_loc, op.value, RO_UNARY_STAR); |
| 6982 | ret.src_range.m_start = op_loc; |
| 6983 | ret.src_range.m_finish = finish; |
| 6984 | return ret; |
| 6985 | } |
| 6986 | case CPP_PLUS: |
| 6987 | if (!c_dialect_objc () && !in_system_header_at (input_location)) |
| 6988 | warning_at (op_loc, |
| 6989 | OPT_Wtraditional, |
| 6990 | "traditional C rejects the unary plus operator" ); |
| 6991 | c_parser_consume_token (parser); |
| 6992 | exp_loc = c_parser_peek_token (parser)->location; |
| 6993 | op = c_parser_cast_expression (parser, NULL); |
| 6994 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
| 6995 | return parser_build_unary_op (op_loc, CONVERT_EXPR, op); |
| 6996 | case CPP_MINUS: |
| 6997 | c_parser_consume_token (parser); |
| 6998 | exp_loc = c_parser_peek_token (parser)->location; |
| 6999 | op = c_parser_cast_expression (parser, NULL); |
| 7000 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
| 7001 | return parser_build_unary_op (op_loc, NEGATE_EXPR, op); |
| 7002 | case CPP_COMPL: |
| 7003 | c_parser_consume_token (parser); |
| 7004 | exp_loc = c_parser_peek_token (parser)->location; |
| 7005 | op = c_parser_cast_expression (parser, NULL); |
| 7006 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
| 7007 | return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op); |
| 7008 | case CPP_NOT: |
| 7009 | c_parser_consume_token (parser); |
| 7010 | exp_loc = c_parser_peek_token (parser)->location; |
| 7011 | op = c_parser_cast_expression (parser, NULL); |
| 7012 | op = convert_lvalue_to_rvalue (exp_loc, op, true, true); |
| 7013 | return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op); |
| 7014 | case CPP_AND_AND: |
| 7015 | /* Refer to the address of a label as a pointer. */ |
| 7016 | c_parser_consume_token (parser); |
| 7017 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 7018 | { |
| 7019 | ret.value = finish_label_address_expr |
| 7020 | (c_parser_peek_token (parser)->value, op_loc); |
| 7021 | set_c_expr_source_range (&ret, op_loc, |
| 7022 | c_parser_peek_token (parser)->get_finish ()); |
| 7023 | c_parser_consume_token (parser); |
| 7024 | } |
| 7025 | else |
| 7026 | { |
| 7027 | c_parser_error (parser, "expected identifier" ); |
| 7028 | ret.value = error_mark_node; |
| 7029 | } |
| 7030 | return ret; |
| 7031 | case CPP_KEYWORD: |
| 7032 | switch (c_parser_peek_token (parser)->keyword) |
| 7033 | { |
| 7034 | case RID_SIZEOF: |
| 7035 | return c_parser_sizeof_expression (parser); |
| 7036 | case RID_ALIGNOF: |
| 7037 | return c_parser_alignof_expression (parser); |
| 7038 | case RID_EXTENSION: |
| 7039 | c_parser_consume_token (parser); |
| 7040 | ext = disable_extension_diagnostics (); |
| 7041 | ret = c_parser_cast_expression (parser, NULL); |
| 7042 | restore_extension_diagnostics (ext); |
| 7043 | return ret; |
| 7044 | case RID_REALPART: |
| 7045 | c_parser_consume_token (parser); |
| 7046 | exp_loc = c_parser_peek_token (parser)->location; |
| 7047 | op = c_parser_cast_expression (parser, NULL); |
| 7048 | op = default_function_array_conversion (exp_loc, op); |
| 7049 | return parser_build_unary_op (op_loc, REALPART_EXPR, op); |
| 7050 | case RID_IMAGPART: |
| 7051 | c_parser_consume_token (parser); |
| 7052 | exp_loc = c_parser_peek_token (parser)->location; |
| 7053 | op = c_parser_cast_expression (parser, NULL); |
| 7054 | op = default_function_array_conversion (exp_loc, op); |
| 7055 | return parser_build_unary_op (op_loc, IMAGPART_EXPR, op); |
| 7056 | case RID_TRANSACTION_ATOMIC: |
| 7057 | case RID_TRANSACTION_RELAXED: |
| 7058 | return c_parser_transaction_expression (parser, |
| 7059 | c_parser_peek_token (parser)->keyword); |
| 7060 | default: |
| 7061 | return c_parser_postfix_expression (parser); |
| 7062 | } |
| 7063 | default: |
| 7064 | return c_parser_postfix_expression (parser); |
| 7065 | } |
| 7066 | } |
| 7067 | |
| 7068 | /* Parse a sizeof expression. */ |
| 7069 | |
| 7070 | static struct c_expr |
| 7071 | c_parser_sizeof_expression (c_parser *parser) |
| 7072 | { |
| 7073 | struct c_expr expr; |
| 7074 | struct c_expr result; |
| 7075 | location_t expr_loc; |
| 7076 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF)); |
| 7077 | |
| 7078 | location_t start; |
| 7079 | location_t finish = UNKNOWN_LOCATION; |
| 7080 | |
| 7081 | start = c_parser_peek_token (parser)->location; |
| 7082 | |
| 7083 | c_parser_consume_token (parser); |
| 7084 | c_inhibit_evaluation_warnings++; |
| 7085 | in_sizeof++; |
| 7086 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) |
| 7087 | && c_token_starts_typename (c_parser_peek_2nd_token (parser))) |
| 7088 | { |
| 7089 | /* Either sizeof ( type-name ) or sizeof unary-expression |
| 7090 | starting with a compound literal. */ |
| 7091 | struct c_type_name *type_name; |
| 7092 | c_parser_consume_token (parser); |
| 7093 | expr_loc = c_parser_peek_token (parser)->location; |
| 7094 | type_name = c_parser_type_name (parser); |
| 7095 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 7096 | finish = parser->tokens_buf[0].location; |
| 7097 | if (type_name == NULL) |
| 7098 | { |
| 7099 | struct c_expr ret; |
| 7100 | c_inhibit_evaluation_warnings--; |
| 7101 | in_sizeof--; |
| 7102 | ret.value = error_mark_node; |
| 7103 | ret.original_code = ERROR_MARK; |
| 7104 | ret.original_type = NULL; |
| 7105 | return ret; |
| 7106 | } |
| 7107 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 7108 | { |
| 7109 | expr = c_parser_postfix_expression_after_paren_type (parser, |
| 7110 | type_name, |
| 7111 | expr_loc); |
| 7112 | finish = expr.get_finish (); |
| 7113 | goto sizeof_expr; |
| 7114 | } |
| 7115 | /* sizeof ( type-name ). */ |
| 7116 | c_inhibit_evaluation_warnings--; |
| 7117 | in_sizeof--; |
| 7118 | result = c_expr_sizeof_type (expr_loc, type_name); |
| 7119 | } |
| 7120 | else |
| 7121 | { |
| 7122 | expr_loc = c_parser_peek_token (parser)->location; |
| 7123 | expr = c_parser_unary_expression (parser); |
| 7124 | finish = expr.get_finish (); |
| 7125 | sizeof_expr: |
| 7126 | c_inhibit_evaluation_warnings--; |
| 7127 | in_sizeof--; |
| 7128 | mark_exp_read (expr.value); |
| 7129 | if (TREE_CODE (expr.value) == COMPONENT_REF |
| 7130 | && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1))) |
| 7131 | error_at (expr_loc, "%<sizeof%> applied to a bit-field" ); |
| 7132 | result = c_expr_sizeof_expr (expr_loc, expr); |
| 7133 | } |
| 7134 | if (finish != UNKNOWN_LOCATION) |
| 7135 | set_c_expr_source_range (&result, start, finish); |
| 7136 | return result; |
| 7137 | } |
| 7138 | |
| 7139 | /* Parse an alignof expression. */ |
| 7140 | |
| 7141 | static struct c_expr |
| 7142 | c_parser_alignof_expression (c_parser *parser) |
| 7143 | { |
| 7144 | struct c_expr expr; |
| 7145 | location_t start_loc = c_parser_peek_token (parser)->location; |
| 7146 | location_t end_loc; |
| 7147 | tree alignof_spelling = c_parser_peek_token (parser)->value; |
| 7148 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF)); |
| 7149 | bool is_c11_alignof = strcmp (IDENTIFIER_POINTER (alignof_spelling), |
| 7150 | "_Alignof" ) == 0; |
| 7151 | /* A diagnostic is not required for the use of this identifier in |
| 7152 | the implementation namespace; only diagnose it for the C11 |
| 7153 | spelling because of existing code using the other spellings. */ |
| 7154 | if (is_c11_alignof) |
| 7155 | { |
| 7156 | if (flag_isoc99) |
| 7157 | pedwarn_c99 (start_loc, OPT_Wpedantic, "ISO C99 does not support %qE" , |
| 7158 | alignof_spelling); |
| 7159 | else |
| 7160 | pedwarn_c99 (start_loc, OPT_Wpedantic, "ISO C90 does not support %qE" , |
| 7161 | alignof_spelling); |
| 7162 | } |
| 7163 | c_parser_consume_token (parser); |
| 7164 | c_inhibit_evaluation_warnings++; |
| 7165 | in_alignof++; |
| 7166 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) |
| 7167 | && c_token_starts_typename (c_parser_peek_2nd_token (parser))) |
| 7168 | { |
| 7169 | /* Either __alignof__ ( type-name ) or __alignof__ |
| 7170 | unary-expression starting with a compound literal. */ |
| 7171 | location_t loc; |
| 7172 | struct c_type_name *type_name; |
| 7173 | struct c_expr ret; |
| 7174 | c_parser_consume_token (parser); |
| 7175 | loc = c_parser_peek_token (parser)->location; |
| 7176 | type_name = c_parser_type_name (parser); |
| 7177 | end_loc = c_parser_peek_token (parser)->location; |
| 7178 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 7179 | if (type_name == NULL) |
| 7180 | { |
| 7181 | struct c_expr ret; |
| 7182 | c_inhibit_evaluation_warnings--; |
| 7183 | in_alignof--; |
| 7184 | ret.value = error_mark_node; |
| 7185 | ret.original_code = ERROR_MARK; |
| 7186 | ret.original_type = NULL; |
| 7187 | return ret; |
| 7188 | } |
| 7189 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 7190 | { |
| 7191 | expr = c_parser_postfix_expression_after_paren_type (parser, |
| 7192 | type_name, |
| 7193 | loc); |
| 7194 | goto alignof_expr; |
| 7195 | } |
| 7196 | /* alignof ( type-name ). */ |
| 7197 | c_inhibit_evaluation_warnings--; |
| 7198 | in_alignof--; |
| 7199 | ret.value = c_sizeof_or_alignof_type (loc, groktypename (type_name, |
| 7200 | NULL, NULL), |
| 7201 | false, is_c11_alignof, 1); |
| 7202 | ret.original_code = ERROR_MARK; |
| 7203 | ret.original_type = NULL; |
| 7204 | set_c_expr_source_range (&ret, start_loc, end_loc); |
| 7205 | return ret; |
| 7206 | } |
| 7207 | else |
| 7208 | { |
| 7209 | struct c_expr ret; |
| 7210 | expr = c_parser_unary_expression (parser); |
| 7211 | end_loc = expr.src_range.m_finish; |
| 7212 | alignof_expr: |
| 7213 | mark_exp_read (expr.value); |
| 7214 | c_inhibit_evaluation_warnings--; |
| 7215 | in_alignof--; |
| 7216 | if (is_c11_alignof) |
| 7217 | pedwarn (start_loc, |
| 7218 | OPT_Wpedantic, "ISO C does not allow %<%E (expression)%>" , |
| 7219 | alignof_spelling); |
| 7220 | ret.value = c_alignof_expr (start_loc, expr.value); |
| 7221 | ret.original_code = ERROR_MARK; |
| 7222 | ret.original_type = NULL; |
| 7223 | set_c_expr_source_range (&ret, start_loc, end_loc); |
| 7224 | return ret; |
| 7225 | } |
| 7226 | } |
| 7227 | |
| 7228 | /* Helper function to read arguments of builtins which are interfaces |
| 7229 | for the middle-end nodes like COMPLEX_EXPR, VEC_PERM_EXPR and |
| 7230 | others. The name of the builtin is passed using BNAME parameter. |
| 7231 | Function returns true if there were no errors while parsing and |
| 7232 | stores the arguments in CEXPR_LIST. If it returns true, |
| 7233 | *OUT_CLOSE_PAREN_LOC is written to with the location of the closing |
| 7234 | parenthesis. */ |
| 7235 | static bool |
| 7236 | c_parser_get_builtin_args (c_parser *parser, const char *bname, |
| 7237 | vec<c_expr_t, va_gc> **ret_cexpr_list, |
| 7238 | bool choose_expr_p, |
| 7239 | location_t *out_close_paren_loc) |
| 7240 | { |
| 7241 | location_t loc = c_parser_peek_token (parser)->location; |
| 7242 | vec<c_expr_t, va_gc> *cexpr_list; |
| 7243 | c_expr_t expr; |
| 7244 | bool saved_force_folding_builtin_constant_p; |
| 7245 | |
| 7246 | *ret_cexpr_list = NULL; |
| 7247 | if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN)) |
| 7248 | { |
| 7249 | error_at (loc, "cannot take address of %qs" , bname); |
| 7250 | return false; |
| 7251 | } |
| 7252 | |
| 7253 | c_parser_consume_token (parser); |
| 7254 | |
| 7255 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 7256 | { |
| 7257 | *out_close_paren_loc = c_parser_peek_token (parser)->location; |
| 7258 | c_parser_consume_token (parser); |
| 7259 | return true; |
| 7260 | } |
| 7261 | |
| 7262 | saved_force_folding_builtin_constant_p |
| 7263 | = force_folding_builtin_constant_p; |
| 7264 | force_folding_builtin_constant_p |= choose_expr_p; |
| 7265 | expr = c_parser_expr_no_commas (parser, NULL); |
| 7266 | force_folding_builtin_constant_p |
| 7267 | = saved_force_folding_builtin_constant_p; |
| 7268 | vec_alloc (cexpr_list, 1); |
| 7269 | vec_safe_push (cexpr_list, expr); |
| 7270 | while (c_parser_next_token_is (parser, CPP_COMMA)) |
| 7271 | { |
| 7272 | c_parser_consume_token (parser); |
| 7273 | expr = c_parser_expr_no_commas (parser, NULL); |
| 7274 | vec_safe_push (cexpr_list, expr); |
| 7275 | } |
| 7276 | |
| 7277 | *out_close_paren_loc = c_parser_peek_token (parser)->location; |
| 7278 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>" )) |
| 7279 | return false; |
| 7280 | |
| 7281 | *ret_cexpr_list = cexpr_list; |
| 7282 | return true; |
| 7283 | } |
| 7284 | |
| 7285 | /* This represents a single generic-association. */ |
| 7286 | |
| 7287 | struct c_generic_association |
| 7288 | { |
| 7289 | /* The location of the starting token of the type. */ |
| 7290 | location_t type_location; |
| 7291 | /* The association's type, or NULL_TREE for 'default'. */ |
| 7292 | tree type; |
| 7293 | /* The association's expression. */ |
| 7294 | struct c_expr expression; |
| 7295 | }; |
| 7296 | |
| 7297 | /* Parse a generic-selection. (C11 6.5.1.1). |
| 7298 | |
| 7299 | generic-selection: |
| 7300 | _Generic ( assignment-expression , generic-assoc-list ) |
| 7301 | |
| 7302 | generic-assoc-list: |
| 7303 | generic-association |
| 7304 | generic-assoc-list , generic-association |
| 7305 | |
| 7306 | generic-association: |
| 7307 | type-name : assignment-expression |
| 7308 | default : assignment-expression |
| 7309 | */ |
| 7310 | |
| 7311 | static struct c_expr |
| 7312 | c_parser_generic_selection (c_parser *parser) |
| 7313 | { |
| 7314 | struct c_expr selector, error_expr; |
| 7315 | tree selector_type; |
| 7316 | struct c_generic_association matched_assoc; |
| 7317 | bool match_found = false; |
| 7318 | location_t generic_loc, selector_loc; |
| 7319 | |
| 7320 | error_expr.original_code = ERROR_MARK; |
| 7321 | error_expr.original_type = NULL; |
| 7322 | error_expr.set_error (); |
| 7323 | matched_assoc.type_location = UNKNOWN_LOCATION; |
| 7324 | matched_assoc.type = NULL_TREE; |
| 7325 | matched_assoc.expression = error_expr; |
| 7326 | |
| 7327 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_GENERIC)); |
| 7328 | generic_loc = c_parser_peek_token (parser)->location; |
| 7329 | c_parser_consume_token (parser); |
| 7330 | if (flag_isoc99) |
| 7331 | pedwarn_c99 (generic_loc, OPT_Wpedantic, |
| 7332 | "ISO C99 does not support %<_Generic%>" ); |
| 7333 | else |
| 7334 | pedwarn_c99 (generic_loc, OPT_Wpedantic, |
| 7335 | "ISO C90 does not support %<_Generic%>" ); |
| 7336 | |
| 7337 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 7338 | return error_expr; |
| 7339 | |
| 7340 | c_inhibit_evaluation_warnings++; |
| 7341 | selector_loc = c_parser_peek_token (parser)->location; |
| 7342 | selector = c_parser_expr_no_commas (parser, NULL); |
| 7343 | selector = default_function_array_conversion (selector_loc, selector); |
| 7344 | c_inhibit_evaluation_warnings--; |
| 7345 | |
| 7346 | if (selector.value == error_mark_node) |
| 7347 | { |
| 7348 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 7349 | return selector; |
| 7350 | } |
| 7351 | selector_type = TREE_TYPE (selector.value); |
| 7352 | /* In ISO C terms, rvalues (including the controlling expression of |
| 7353 | _Generic) do not have qualified types. */ |
| 7354 | if (TREE_CODE (selector_type) != ARRAY_TYPE) |
| 7355 | selector_type = TYPE_MAIN_VARIANT (selector_type); |
| 7356 | /* In ISO C terms, _Noreturn is not part of the type of expressions |
| 7357 | such as &abort, but in GCC it is represented internally as a type |
| 7358 | qualifier. */ |
| 7359 | if (FUNCTION_POINTER_TYPE_P (selector_type) |
| 7360 | && TYPE_QUALS (TREE_TYPE (selector_type)) != TYPE_UNQUALIFIED) |
| 7361 | selector_type |
| 7362 | = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type))); |
| 7363 | |
| 7364 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>" )) |
| 7365 | { |
| 7366 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 7367 | return error_expr; |
| 7368 | } |
| 7369 | |
| 7370 | auto_vec<c_generic_association> associations; |
| 7371 | while (1) |
| 7372 | { |
| 7373 | struct c_generic_association assoc, *iter; |
| 7374 | unsigned int ix; |
| 7375 | c_token *token = c_parser_peek_token (parser); |
| 7376 | |
| 7377 | assoc.type_location = token->location; |
| 7378 | if (token->type == CPP_KEYWORD && token->keyword == RID_DEFAULT) |
| 7379 | { |
| 7380 | c_parser_consume_token (parser); |
| 7381 | assoc.type = NULL_TREE; |
| 7382 | } |
| 7383 | else |
| 7384 | { |
| 7385 | struct c_type_name *type_name; |
| 7386 | |
| 7387 | type_name = c_parser_type_name (parser); |
| 7388 | if (type_name == NULL) |
| 7389 | { |
| 7390 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 7391 | return error_expr; |
| 7392 | } |
| 7393 | assoc.type = groktypename (type_name, NULL, NULL); |
| 7394 | if (assoc.type == error_mark_node) |
| 7395 | { |
| 7396 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 7397 | return error_expr; |
| 7398 | } |
| 7399 | |
| 7400 | if (TREE_CODE (assoc.type) == FUNCTION_TYPE) |
| 7401 | error_at (assoc.type_location, |
| 7402 | "%<_Generic%> association has function type" ); |
| 7403 | else if (!COMPLETE_TYPE_P (assoc.type)) |
| 7404 | error_at (assoc.type_location, |
| 7405 | "%<_Generic%> association has incomplete type" ); |
| 7406 | |
| 7407 | if (variably_modified_type_p (assoc.type, NULL_TREE)) |
| 7408 | error_at (assoc.type_location, |
| 7409 | "%<_Generic%> association has " |
| 7410 | "variable length type" ); |
| 7411 | } |
| 7412 | |
| 7413 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>" )) |
| 7414 | { |
| 7415 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 7416 | return error_expr; |
| 7417 | } |
| 7418 | |
| 7419 | assoc.expression = c_parser_expr_no_commas (parser, NULL); |
| 7420 | if (assoc.expression.value == error_mark_node) |
| 7421 | { |
| 7422 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 7423 | return error_expr; |
| 7424 | } |
| 7425 | |
| 7426 | for (ix = 0; associations.iterate (ix, &iter); ++ix) |
| 7427 | { |
| 7428 | if (assoc.type == NULL_TREE) |
| 7429 | { |
| 7430 | if (iter->type == NULL_TREE) |
| 7431 | { |
| 7432 | error_at (assoc.type_location, |
| 7433 | "duplicate %<default%> case in %<_Generic%>" ); |
| 7434 | inform (iter->type_location, "original %<default%> is here" ); |
| 7435 | } |
| 7436 | } |
| 7437 | else if (iter->type != NULL_TREE) |
| 7438 | { |
| 7439 | if (comptypes (assoc.type, iter->type)) |
| 7440 | { |
| 7441 | error_at (assoc.type_location, |
| 7442 | "%<_Generic%> specifies two compatible types" ); |
| 7443 | inform (iter->type_location, "compatible type is here" ); |
| 7444 | } |
| 7445 | } |
| 7446 | } |
| 7447 | |
| 7448 | if (assoc.type == NULL_TREE) |
| 7449 | { |
| 7450 | if (!match_found) |
| 7451 | { |
| 7452 | matched_assoc = assoc; |
| 7453 | match_found = true; |
| 7454 | } |
| 7455 | } |
| 7456 | else if (comptypes (assoc.type, selector_type)) |
| 7457 | { |
| 7458 | if (!match_found || matched_assoc.type == NULL_TREE) |
| 7459 | { |
| 7460 | matched_assoc = assoc; |
| 7461 | match_found = true; |
| 7462 | } |
| 7463 | else |
| 7464 | { |
| 7465 | error_at (assoc.type_location, |
| 7466 | "%<_Generic%> selector matches multiple associations" ); |
| 7467 | inform (matched_assoc.type_location, |
| 7468 | "other match is here" ); |
| 7469 | } |
| 7470 | } |
| 7471 | |
| 7472 | associations.safe_push (assoc); |
| 7473 | |
| 7474 | if (c_parser_peek_token (parser)->type != CPP_COMMA) |
| 7475 | break; |
| 7476 | c_parser_consume_token (parser); |
| 7477 | } |
| 7478 | |
| 7479 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>" )) |
| 7480 | { |
| 7481 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 7482 | return error_expr; |
| 7483 | } |
| 7484 | |
| 7485 | if (!match_found) |
| 7486 | { |
| 7487 | error_at (selector_loc, "%<_Generic%> selector of type %qT is not " |
| 7488 | "compatible with any association" , |
| 7489 | selector_type); |
| 7490 | return error_expr; |
| 7491 | } |
| 7492 | |
| 7493 | return matched_assoc.expression; |
| 7494 | } |
| 7495 | |
| 7496 | /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2, |
| 7497 | C11 6.5.1-6.5.2). |
| 7498 | |
| 7499 | postfix-expression: |
| 7500 | primary-expression |
| 7501 | postfix-expression [ expression ] |
| 7502 | postfix-expression ( argument-expression-list[opt] ) |
| 7503 | postfix-expression . identifier |
| 7504 | postfix-expression -> identifier |
| 7505 | postfix-expression ++ |
| 7506 | postfix-expression -- |
| 7507 | ( type-name ) { initializer-list } |
| 7508 | ( type-name ) { initializer-list , } |
| 7509 | |
| 7510 | argument-expression-list: |
| 7511 | argument-expression |
| 7512 | argument-expression-list , argument-expression |
| 7513 | |
| 7514 | primary-expression: |
| 7515 | identifier |
| 7516 | constant |
| 7517 | string-literal |
| 7518 | ( expression ) |
| 7519 | generic-selection |
| 7520 | |
| 7521 | GNU extensions: |
| 7522 | |
| 7523 | primary-expression: |
| 7524 | __func__ |
| 7525 | (treated as a keyword in GNU C) |
| 7526 | __FUNCTION__ |
| 7527 | __PRETTY_FUNCTION__ |
| 7528 | ( compound-statement ) |
| 7529 | __builtin_va_arg ( assignment-expression , type-name ) |
| 7530 | __builtin_offsetof ( type-name , offsetof-member-designator ) |
| 7531 | __builtin_choose_expr ( assignment-expression , |
| 7532 | assignment-expression , |
| 7533 | assignment-expression ) |
| 7534 | __builtin_types_compatible_p ( type-name , type-name ) |
| 7535 | __builtin_complex ( assignment-expression , assignment-expression ) |
| 7536 | __builtin_shuffle ( assignment-expression , assignment-expression ) |
| 7537 | __builtin_shuffle ( assignment-expression , |
| 7538 | assignment-expression , |
| 7539 | assignment-expression, ) |
| 7540 | |
| 7541 | offsetof-member-designator: |
| 7542 | identifier |
| 7543 | offsetof-member-designator . identifier |
| 7544 | offsetof-member-designator [ expression ] |
| 7545 | |
| 7546 | Objective-C: |
| 7547 | |
| 7548 | primary-expression: |
| 7549 | [ objc-receiver objc-message-args ] |
| 7550 | @selector ( objc-selector-arg ) |
| 7551 | @protocol ( identifier ) |
| 7552 | @encode ( type-name ) |
| 7553 | objc-string-literal |
| 7554 | Classname . identifier |
| 7555 | */ |
| 7556 | |
| 7557 | static struct c_expr |
| 7558 | c_parser_postfix_expression (c_parser *parser) |
| 7559 | { |
| 7560 | struct c_expr expr, e1; |
| 7561 | struct c_type_name *t1, *t2; |
| 7562 | location_t loc = c_parser_peek_token (parser)->location;; |
| 7563 | source_range tok_range = c_parser_peek_token (parser)->get_range (); |
| 7564 | expr.original_code = ERROR_MARK; |
| 7565 | expr.original_type = NULL; |
| 7566 | switch (c_parser_peek_token (parser)->type) |
| 7567 | { |
| 7568 | case CPP_NUMBER: |
| 7569 | expr.value = c_parser_peek_token (parser)->value; |
| 7570 | set_c_expr_source_range (&expr, tok_range); |
| 7571 | loc = c_parser_peek_token (parser)->location; |
| 7572 | c_parser_consume_token (parser); |
| 7573 | if (TREE_CODE (expr.value) == FIXED_CST |
| 7574 | && !targetm.fixed_point_supported_p ()) |
| 7575 | { |
| 7576 | error_at (loc, "fixed-point types not supported for this target" ); |
| 7577 | expr.value = error_mark_node; |
| 7578 | } |
| 7579 | break; |
| 7580 | case CPP_CHAR: |
| 7581 | case CPP_CHAR16: |
| 7582 | case CPP_CHAR32: |
| 7583 | case CPP_WCHAR: |
| 7584 | expr.value = c_parser_peek_token (parser)->value; |
| 7585 | /* For the purpose of warning when a pointer is compared with |
| 7586 | a zero character constant. */ |
| 7587 | expr.original_type = char_type_node; |
| 7588 | set_c_expr_source_range (&expr, tok_range); |
| 7589 | c_parser_consume_token (parser); |
| 7590 | break; |
| 7591 | case CPP_STRING: |
| 7592 | case CPP_STRING16: |
| 7593 | case CPP_STRING32: |
| 7594 | case CPP_WSTRING: |
| 7595 | case CPP_UTF8STRING: |
| 7596 | expr.value = c_parser_peek_token (parser)->value; |
| 7597 | set_c_expr_source_range (&expr, tok_range); |
| 7598 | expr.original_code = STRING_CST; |
| 7599 | c_parser_consume_token (parser); |
| 7600 | break; |
| 7601 | case CPP_OBJC_STRING: |
| 7602 | gcc_assert (c_dialect_objc ()); |
| 7603 | expr.value |
| 7604 | = objc_build_string_object (c_parser_peek_token (parser)->value); |
| 7605 | set_c_expr_source_range (&expr, tok_range); |
| 7606 | c_parser_consume_token (parser); |
| 7607 | break; |
| 7608 | case CPP_NAME: |
| 7609 | switch (c_parser_peek_token (parser)->id_kind) |
| 7610 | { |
| 7611 | case C_ID_ID: |
| 7612 | { |
| 7613 | tree id = c_parser_peek_token (parser)->value; |
| 7614 | c_parser_consume_token (parser); |
| 7615 | expr.value = build_external_ref (loc, id, |
| 7616 | (c_parser_peek_token (parser)->type |
| 7617 | == CPP_OPEN_PAREN), |
| 7618 | &expr.original_type); |
| 7619 | set_c_expr_source_range (&expr, tok_range); |
| 7620 | break; |
| 7621 | } |
| 7622 | case C_ID_CLASSNAME: |
| 7623 | { |
| 7624 | /* Here we parse the Objective-C 2.0 Class.name dot |
| 7625 | syntax. */ |
| 7626 | tree class_name = c_parser_peek_token (parser)->value; |
| 7627 | tree component; |
| 7628 | c_parser_consume_token (parser); |
| 7629 | gcc_assert (c_dialect_objc ()); |
| 7630 | if (!c_parser_require (parser, CPP_DOT, "expected %<.%>" )) |
| 7631 | { |
| 7632 | expr.set_error (); |
| 7633 | break; |
| 7634 | } |
| 7635 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 7636 | { |
| 7637 | c_parser_error (parser, "expected identifier" ); |
| 7638 | expr.set_error (); |
| 7639 | break; |
| 7640 | } |
| 7641 | c_token *component_tok = c_parser_peek_token (parser); |
| 7642 | component = component_tok->value; |
| 7643 | location_t end_loc = component_tok->get_finish (); |
| 7644 | c_parser_consume_token (parser); |
| 7645 | expr.value = objc_build_class_component_ref (class_name, |
| 7646 | component); |
| 7647 | set_c_expr_source_range (&expr, loc, end_loc); |
| 7648 | break; |
| 7649 | } |
| 7650 | default: |
| 7651 | c_parser_error (parser, "expected expression" ); |
| 7652 | expr.set_error (); |
| 7653 | break; |
| 7654 | } |
| 7655 | break; |
| 7656 | case CPP_OPEN_PAREN: |
| 7657 | /* A parenthesized expression, statement expression or compound |
| 7658 | literal. */ |
| 7659 | if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE) |
| 7660 | { |
| 7661 | /* A statement expression. */ |
| 7662 | tree stmt; |
| 7663 | location_t brace_loc; |
| 7664 | c_parser_consume_token (parser); |
| 7665 | brace_loc = c_parser_peek_token (parser)->location; |
| 7666 | c_parser_consume_token (parser); |
| 7667 | if (!building_stmt_list_p ()) |
| 7668 | { |
| 7669 | error_at (loc, "braced-group within expression allowed " |
| 7670 | "only inside a function" ); |
| 7671 | parser->error = true; |
| 7672 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); |
| 7673 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 7674 | expr.set_error (); |
| 7675 | break; |
| 7676 | } |
| 7677 | stmt = c_begin_stmt_expr (); |
| 7678 | c_parser_compound_statement_nostart (parser); |
| 7679 | location_t close_loc = c_parser_peek_token (parser)->location; |
| 7680 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 7681 | "expected %<)%>" ); |
| 7682 | pedwarn (loc, OPT_Wpedantic, |
| 7683 | "ISO C forbids braced-groups within expressions" ); |
| 7684 | expr.value = c_finish_stmt_expr (brace_loc, stmt); |
| 7685 | set_c_expr_source_range (&expr, loc, close_loc); |
| 7686 | mark_exp_read (expr.value); |
| 7687 | } |
| 7688 | else if (c_token_starts_typename (c_parser_peek_2nd_token (parser))) |
| 7689 | { |
| 7690 | /* A compound literal. ??? Can we actually get here rather |
| 7691 | than going directly to |
| 7692 | c_parser_postfix_expression_after_paren_type from |
| 7693 | elsewhere? */ |
| 7694 | location_t loc; |
| 7695 | struct c_type_name *type_name; |
| 7696 | c_parser_consume_token (parser); |
| 7697 | loc = c_parser_peek_token (parser)->location; |
| 7698 | type_name = c_parser_type_name (parser); |
| 7699 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 7700 | "expected %<)%>" ); |
| 7701 | if (type_name == NULL) |
| 7702 | { |
| 7703 | expr.set_error (); |
| 7704 | } |
| 7705 | else |
| 7706 | expr = c_parser_postfix_expression_after_paren_type (parser, |
| 7707 | type_name, |
| 7708 | loc); |
| 7709 | } |
| 7710 | else |
| 7711 | { |
| 7712 | /* A parenthesized expression. */ |
| 7713 | location_t loc_open_paren = c_parser_peek_token (parser)->location; |
| 7714 | c_parser_consume_token (parser); |
| 7715 | expr = c_parser_expression (parser); |
| 7716 | if (TREE_CODE (expr.value) == MODIFY_EXPR) |
| 7717 | TREE_NO_WARNING (expr.value) = 1; |
| 7718 | if (expr.original_code != C_MAYBE_CONST_EXPR) |
| 7719 | expr.original_code = ERROR_MARK; |
| 7720 | /* Don't change EXPR.ORIGINAL_TYPE. */ |
| 7721 | location_t loc_close_paren = c_parser_peek_token (parser)->location; |
| 7722 | set_c_expr_source_range (&expr, loc_open_paren, loc_close_paren); |
| 7723 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 7724 | "expected %<)%>" ); |
| 7725 | } |
| 7726 | break; |
| 7727 | case CPP_KEYWORD: |
| 7728 | switch (c_parser_peek_token (parser)->keyword) |
| 7729 | { |
| 7730 | case RID_FUNCTION_NAME: |
| 7731 | pedwarn (loc, OPT_Wpedantic, "ISO C does not support " |
| 7732 | "%<__FUNCTION__%> predefined identifier" ); |
| 7733 | expr.value = fname_decl (loc, |
| 7734 | c_parser_peek_token (parser)->keyword, |
| 7735 | c_parser_peek_token (parser)->value); |
| 7736 | set_c_expr_source_range (&expr, loc, loc); |
| 7737 | c_parser_consume_token (parser); |
| 7738 | break; |
| 7739 | case RID_PRETTY_FUNCTION_NAME: |
| 7740 | pedwarn (loc, OPT_Wpedantic, "ISO C does not support " |
| 7741 | "%<__PRETTY_FUNCTION__%> predefined identifier" ); |
| 7742 | expr.value = fname_decl (loc, |
| 7743 | c_parser_peek_token (parser)->keyword, |
| 7744 | c_parser_peek_token (parser)->value); |
| 7745 | set_c_expr_source_range (&expr, loc, loc); |
| 7746 | c_parser_consume_token (parser); |
| 7747 | break; |
| 7748 | case RID_C99_FUNCTION_NAME: |
| 7749 | pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not support " |
| 7750 | "%<__func__%> predefined identifier" ); |
| 7751 | expr.value = fname_decl (loc, |
| 7752 | c_parser_peek_token (parser)->keyword, |
| 7753 | c_parser_peek_token (parser)->value); |
| 7754 | set_c_expr_source_range (&expr, loc, loc); |
| 7755 | c_parser_consume_token (parser); |
| 7756 | break; |
| 7757 | case RID_VA_ARG: |
| 7758 | { |
| 7759 | location_t start_loc = loc; |
| 7760 | c_parser_consume_token (parser); |
| 7761 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 7762 | { |
| 7763 | expr.set_error (); |
| 7764 | break; |
| 7765 | } |
| 7766 | e1 = c_parser_expr_no_commas (parser, NULL); |
| 7767 | mark_exp_read (e1.value); |
| 7768 | e1.value = c_fully_fold (e1.value, false, NULL); |
| 7769 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>" )) |
| 7770 | { |
| 7771 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 7772 | expr.set_error (); |
| 7773 | break; |
| 7774 | } |
| 7775 | loc = c_parser_peek_token (parser)->location; |
| 7776 | t1 = c_parser_type_name (parser); |
| 7777 | location_t end_loc = c_parser_peek_token (parser)->get_finish (); |
| 7778 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 7779 | "expected %<)%>" ); |
| 7780 | if (t1 == NULL) |
| 7781 | { |
| 7782 | expr.set_error (); |
| 7783 | } |
| 7784 | else |
| 7785 | { |
| 7786 | tree type_expr = NULL_TREE; |
| 7787 | expr.value = c_build_va_arg (start_loc, e1.value, loc, |
| 7788 | groktypename (t1, &type_expr, NULL)); |
| 7789 | if (type_expr) |
| 7790 | { |
| 7791 | expr.value = build2 (C_MAYBE_CONST_EXPR, |
| 7792 | TREE_TYPE (expr.value), type_expr, |
| 7793 | expr.value); |
| 7794 | C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true; |
| 7795 | } |
| 7796 | set_c_expr_source_range (&expr, start_loc, end_loc); |
| 7797 | } |
| 7798 | } |
| 7799 | break; |
| 7800 | case RID_OFFSETOF: |
| 7801 | c_parser_consume_token (parser); |
| 7802 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 7803 | { |
| 7804 | expr.set_error (); |
| 7805 | break; |
| 7806 | } |
| 7807 | t1 = c_parser_type_name (parser); |
| 7808 | if (t1 == NULL) |
| 7809 | parser->error = true; |
| 7810 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>" )) |
| 7811 | gcc_assert (parser->error); |
| 7812 | if (parser->error) |
| 7813 | { |
| 7814 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 7815 | expr.set_error (); |
| 7816 | break; |
| 7817 | } |
| 7818 | |
| 7819 | { |
| 7820 | tree type = groktypename (t1, NULL, NULL); |
| 7821 | tree offsetof_ref; |
| 7822 | if (type == error_mark_node) |
| 7823 | offsetof_ref = error_mark_node; |
| 7824 | else |
| 7825 | { |
| 7826 | offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node); |
| 7827 | SET_EXPR_LOCATION (offsetof_ref, loc); |
| 7828 | } |
| 7829 | /* Parse the second argument to __builtin_offsetof. We |
| 7830 | must have one identifier, and beyond that we want to |
| 7831 | accept sub structure and sub array references. */ |
| 7832 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 7833 | { |
| 7834 | c_token *comp_tok = c_parser_peek_token (parser); |
| 7835 | offsetof_ref = build_component_ref |
| 7836 | (loc, offsetof_ref, comp_tok->value, comp_tok->location); |
| 7837 | c_parser_consume_token (parser); |
| 7838 | while (c_parser_next_token_is (parser, CPP_DOT) |
| 7839 | || c_parser_next_token_is (parser, |
| 7840 | CPP_OPEN_SQUARE) |
| 7841 | || c_parser_next_token_is (parser, |
| 7842 | CPP_DEREF)) |
| 7843 | { |
| 7844 | if (c_parser_next_token_is (parser, CPP_DEREF)) |
| 7845 | { |
| 7846 | loc = c_parser_peek_token (parser)->location; |
| 7847 | offsetof_ref = build_array_ref (loc, |
| 7848 | offsetof_ref, |
| 7849 | integer_zero_node); |
| 7850 | goto do_dot; |
| 7851 | } |
| 7852 | else if (c_parser_next_token_is (parser, CPP_DOT)) |
| 7853 | { |
| 7854 | do_dot: |
| 7855 | c_parser_consume_token (parser); |
| 7856 | if (c_parser_next_token_is_not (parser, |
| 7857 | CPP_NAME)) |
| 7858 | { |
| 7859 | c_parser_error (parser, "expected identifier" ); |
| 7860 | break; |
| 7861 | } |
| 7862 | c_token *comp_tok = c_parser_peek_token (parser); |
| 7863 | offsetof_ref = build_component_ref |
| 7864 | (loc, offsetof_ref, comp_tok->value, |
| 7865 | comp_tok->location); |
| 7866 | c_parser_consume_token (parser); |
| 7867 | } |
| 7868 | else |
| 7869 | { |
| 7870 | struct c_expr ce; |
| 7871 | tree idx; |
| 7872 | loc = c_parser_peek_token (parser)->location; |
| 7873 | c_parser_consume_token (parser); |
| 7874 | ce = c_parser_expression (parser); |
| 7875 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); |
| 7876 | idx = ce.value; |
| 7877 | idx = c_fully_fold (idx, false, NULL); |
| 7878 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, |
| 7879 | "expected %<]%>" ); |
| 7880 | offsetof_ref = build_array_ref (loc, offsetof_ref, idx); |
| 7881 | } |
| 7882 | } |
| 7883 | } |
| 7884 | else |
| 7885 | c_parser_error (parser, "expected identifier" ); |
| 7886 | location_t end_loc = c_parser_peek_token (parser)->get_finish (); |
| 7887 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 7888 | "expected %<)%>" ); |
| 7889 | expr.value = fold_offsetof (offsetof_ref); |
| 7890 | set_c_expr_source_range (&expr, loc, end_loc); |
| 7891 | } |
| 7892 | break; |
| 7893 | case RID_CHOOSE_EXPR: |
| 7894 | { |
| 7895 | vec<c_expr_t, va_gc> *cexpr_list; |
| 7896 | c_expr_t *e1_p, *e2_p, *e3_p; |
| 7897 | tree c; |
| 7898 | location_t close_paren_loc; |
| 7899 | |
| 7900 | c_parser_consume_token (parser); |
| 7901 | if (!c_parser_get_builtin_args (parser, |
| 7902 | "__builtin_choose_expr" , |
| 7903 | &cexpr_list, true, |
| 7904 | &close_paren_loc)) |
| 7905 | { |
| 7906 | expr.set_error (); |
| 7907 | break; |
| 7908 | } |
| 7909 | |
| 7910 | if (vec_safe_length (cexpr_list) != 3) |
| 7911 | { |
| 7912 | error_at (loc, "wrong number of arguments to " |
| 7913 | "%<__builtin_choose_expr%>" ); |
| 7914 | expr.set_error (); |
| 7915 | break; |
| 7916 | } |
| 7917 | |
| 7918 | e1_p = &(*cexpr_list)[0]; |
| 7919 | e2_p = &(*cexpr_list)[1]; |
| 7920 | e3_p = &(*cexpr_list)[2]; |
| 7921 | |
| 7922 | c = e1_p->value; |
| 7923 | mark_exp_read (e2_p->value); |
| 7924 | mark_exp_read (e3_p->value); |
| 7925 | if (TREE_CODE (c) != INTEGER_CST |
| 7926 | || !INTEGRAL_TYPE_P (TREE_TYPE (c))) |
| 7927 | error_at (loc, |
| 7928 | "first argument to %<__builtin_choose_expr%> not" |
| 7929 | " a constant" ); |
| 7930 | constant_expression_warning (c); |
| 7931 | expr = integer_zerop (c) ? *e3_p : *e2_p; |
| 7932 | set_c_expr_source_range (&expr, loc, close_paren_loc); |
| 7933 | break; |
| 7934 | } |
| 7935 | case RID_TYPES_COMPATIBLE_P: |
| 7936 | c_parser_consume_token (parser); |
| 7937 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 7938 | { |
| 7939 | expr.set_error (); |
| 7940 | break; |
| 7941 | } |
| 7942 | t1 = c_parser_type_name (parser); |
| 7943 | if (t1 == NULL) |
| 7944 | { |
| 7945 | expr.set_error (); |
| 7946 | break; |
| 7947 | } |
| 7948 | if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>" )) |
| 7949 | { |
| 7950 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 7951 | expr.set_error (); |
| 7952 | break; |
| 7953 | } |
| 7954 | t2 = c_parser_type_name (parser); |
| 7955 | if (t2 == NULL) |
| 7956 | { |
| 7957 | expr.set_error (); |
| 7958 | break; |
| 7959 | } |
| 7960 | { |
| 7961 | location_t close_paren_loc = c_parser_peek_token (parser)->location; |
| 7962 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 7963 | "expected %<)%>" ); |
| 7964 | tree e1, e2; |
| 7965 | e1 = groktypename (t1, NULL, NULL); |
| 7966 | e2 = groktypename (t2, NULL, NULL); |
| 7967 | if (e1 == error_mark_node || e2 == error_mark_node) |
| 7968 | { |
| 7969 | expr.set_error (); |
| 7970 | break; |
| 7971 | } |
| 7972 | |
| 7973 | e1 = TYPE_MAIN_VARIANT (e1); |
| 7974 | e2 = TYPE_MAIN_VARIANT (e2); |
| 7975 | |
| 7976 | expr.value |
| 7977 | = comptypes (e1, e2) ? integer_one_node : integer_zero_node; |
| 7978 | set_c_expr_source_range (&expr, loc, close_paren_loc); |
| 7979 | } |
| 7980 | break; |
| 7981 | case RID_BUILTIN_CALL_WITH_STATIC_CHAIN: |
| 7982 | { |
| 7983 | vec<c_expr_t, va_gc> *cexpr_list; |
| 7984 | c_expr_t *e2_p; |
| 7985 | tree chain_value; |
| 7986 | location_t close_paren_loc; |
| 7987 | |
| 7988 | c_parser_consume_token (parser); |
| 7989 | if (!c_parser_get_builtin_args (parser, |
| 7990 | "__builtin_call_with_static_chain" , |
| 7991 | &cexpr_list, false, |
| 7992 | &close_paren_loc)) |
| 7993 | { |
| 7994 | expr.set_error (); |
| 7995 | break; |
| 7996 | } |
| 7997 | if (vec_safe_length (cexpr_list) != 2) |
| 7998 | { |
| 7999 | error_at (loc, "wrong number of arguments to " |
| 8000 | "%<__builtin_call_with_static_chain%>" ); |
| 8001 | expr.set_error (); |
| 8002 | break; |
| 8003 | } |
| 8004 | |
| 8005 | expr = (*cexpr_list)[0]; |
| 8006 | e2_p = &(*cexpr_list)[1]; |
| 8007 | *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true); |
| 8008 | chain_value = e2_p->value; |
| 8009 | mark_exp_read (chain_value); |
| 8010 | |
| 8011 | if (TREE_CODE (expr.value) != CALL_EXPR) |
| 8012 | error_at (loc, "first argument to " |
| 8013 | "%<__builtin_call_with_static_chain%> " |
| 8014 | "must be a call expression" ); |
| 8015 | else if (TREE_CODE (TREE_TYPE (chain_value)) != POINTER_TYPE) |
| 8016 | error_at (loc, "second argument to " |
| 8017 | "%<__builtin_call_with_static_chain%> " |
| 8018 | "must be a pointer type" ); |
| 8019 | else |
| 8020 | CALL_EXPR_STATIC_CHAIN (expr.value) = chain_value; |
| 8021 | set_c_expr_source_range (&expr, loc, close_paren_loc); |
| 8022 | break; |
| 8023 | } |
| 8024 | case RID_BUILTIN_COMPLEX: |
| 8025 | { |
| 8026 | vec<c_expr_t, va_gc> *cexpr_list; |
| 8027 | c_expr_t *e1_p, *e2_p; |
| 8028 | location_t close_paren_loc; |
| 8029 | |
| 8030 | c_parser_consume_token (parser); |
| 8031 | if (!c_parser_get_builtin_args (parser, |
| 8032 | "__builtin_complex" , |
| 8033 | &cexpr_list, false, |
| 8034 | &close_paren_loc)) |
| 8035 | { |
| 8036 | expr.set_error (); |
| 8037 | break; |
| 8038 | } |
| 8039 | |
| 8040 | if (vec_safe_length (cexpr_list) != 2) |
| 8041 | { |
| 8042 | error_at (loc, "wrong number of arguments to " |
| 8043 | "%<__builtin_complex%>" ); |
| 8044 | expr.set_error (); |
| 8045 | break; |
| 8046 | } |
| 8047 | |
| 8048 | e1_p = &(*cexpr_list)[0]; |
| 8049 | e2_p = &(*cexpr_list)[1]; |
| 8050 | |
| 8051 | *e1_p = convert_lvalue_to_rvalue (loc, *e1_p, true, true); |
| 8052 | if (TREE_CODE (e1_p->value) == EXCESS_PRECISION_EXPR) |
| 8053 | e1_p->value = convert (TREE_TYPE (e1_p->value), |
| 8054 | TREE_OPERAND (e1_p->value, 0)); |
| 8055 | *e2_p = convert_lvalue_to_rvalue (loc, *e2_p, true, true); |
| 8056 | if (TREE_CODE (e2_p->value) == EXCESS_PRECISION_EXPR) |
| 8057 | e2_p->value = convert (TREE_TYPE (e2_p->value), |
| 8058 | TREE_OPERAND (e2_p->value, 0)); |
| 8059 | if (!SCALAR_FLOAT_TYPE_P (TREE_TYPE (e1_p->value)) |
| 8060 | || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e1_p->value)) |
| 8061 | || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (e2_p->value)) |
| 8062 | || DECIMAL_FLOAT_TYPE_P (TREE_TYPE (e2_p->value))) |
| 8063 | { |
| 8064 | error_at (loc, "%<__builtin_complex%> operand " |
| 8065 | "not of real binary floating-point type" ); |
| 8066 | expr.set_error (); |
| 8067 | break; |
| 8068 | } |
| 8069 | if (TYPE_MAIN_VARIANT (TREE_TYPE (e1_p->value)) |
| 8070 | != TYPE_MAIN_VARIANT (TREE_TYPE (e2_p->value))) |
| 8071 | { |
| 8072 | error_at (loc, |
| 8073 | "%<__builtin_complex%> operands of different types" ); |
| 8074 | expr.set_error (); |
| 8075 | break; |
| 8076 | } |
| 8077 | pedwarn_c90 (loc, OPT_Wpedantic, |
| 8078 | "ISO C90 does not support complex types" ); |
| 8079 | expr.value = build2_loc (loc, COMPLEX_EXPR, |
| 8080 | build_complex_type |
| 8081 | (TYPE_MAIN_VARIANT |
| 8082 | (TREE_TYPE (e1_p->value))), |
| 8083 | e1_p->value, e2_p->value); |
| 8084 | set_c_expr_source_range (&expr, loc, close_paren_loc); |
| 8085 | break; |
| 8086 | } |
| 8087 | case RID_BUILTIN_SHUFFLE: |
| 8088 | { |
| 8089 | vec<c_expr_t, va_gc> *cexpr_list; |
| 8090 | unsigned int i; |
| 8091 | c_expr_t *p; |
| 8092 | location_t close_paren_loc; |
| 8093 | |
| 8094 | c_parser_consume_token (parser); |
| 8095 | if (!c_parser_get_builtin_args (parser, |
| 8096 | "__builtin_shuffle" , |
| 8097 | &cexpr_list, false, |
| 8098 | &close_paren_loc)) |
| 8099 | { |
| 8100 | expr.set_error (); |
| 8101 | break; |
| 8102 | } |
| 8103 | |
| 8104 | FOR_EACH_VEC_SAFE_ELT (cexpr_list, i, p) |
| 8105 | *p = convert_lvalue_to_rvalue (loc, *p, true, true); |
| 8106 | |
| 8107 | if (vec_safe_length (cexpr_list) == 2) |
| 8108 | expr.value = |
| 8109 | c_build_vec_perm_expr |
| 8110 | (loc, (*cexpr_list)[0].value, |
| 8111 | NULL_TREE, (*cexpr_list)[1].value); |
| 8112 | |
| 8113 | else if (vec_safe_length (cexpr_list) == 3) |
| 8114 | expr.value = |
| 8115 | c_build_vec_perm_expr |
| 8116 | (loc, (*cexpr_list)[0].value, |
| 8117 | (*cexpr_list)[1].value, |
| 8118 | (*cexpr_list)[2].value); |
| 8119 | else |
| 8120 | { |
| 8121 | error_at (loc, "wrong number of arguments to " |
| 8122 | "%<__builtin_shuffle%>" ); |
| 8123 | expr.set_error (); |
| 8124 | } |
| 8125 | set_c_expr_source_range (&expr, loc, close_paren_loc); |
| 8126 | break; |
| 8127 | } |
| 8128 | case RID_AT_SELECTOR: |
| 8129 | gcc_assert (c_dialect_objc ()); |
| 8130 | c_parser_consume_token (parser); |
| 8131 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 8132 | { |
| 8133 | expr.set_error (); |
| 8134 | break; |
| 8135 | } |
| 8136 | { |
| 8137 | tree sel = c_parser_objc_selector_arg (parser); |
| 8138 | location_t close_loc = c_parser_peek_token (parser)->location; |
| 8139 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 8140 | "expected %<)%>" ); |
| 8141 | expr.value = objc_build_selector_expr (loc, sel); |
| 8142 | set_c_expr_source_range (&expr, loc, close_loc); |
| 8143 | } |
| 8144 | break; |
| 8145 | case RID_AT_PROTOCOL: |
| 8146 | gcc_assert (c_dialect_objc ()); |
| 8147 | c_parser_consume_token (parser); |
| 8148 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 8149 | { |
| 8150 | expr.set_error (); |
| 8151 | break; |
| 8152 | } |
| 8153 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 8154 | { |
| 8155 | c_parser_error (parser, "expected identifier" ); |
| 8156 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 8157 | expr.set_error (); |
| 8158 | break; |
| 8159 | } |
| 8160 | { |
| 8161 | tree id = c_parser_peek_token (parser)->value; |
| 8162 | c_parser_consume_token (parser); |
| 8163 | location_t close_loc = c_parser_peek_token (parser)->location; |
| 8164 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 8165 | "expected %<)%>" ); |
| 8166 | expr.value = objc_build_protocol_expr (id); |
| 8167 | set_c_expr_source_range (&expr, loc, close_loc); |
| 8168 | } |
| 8169 | break; |
| 8170 | case RID_AT_ENCODE: |
| 8171 | /* Extension to support C-structures in the archiver. */ |
| 8172 | gcc_assert (c_dialect_objc ()); |
| 8173 | c_parser_consume_token (parser); |
| 8174 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 8175 | { |
| 8176 | expr.set_error (); |
| 8177 | break; |
| 8178 | } |
| 8179 | t1 = c_parser_type_name (parser); |
| 8180 | if (t1 == NULL) |
| 8181 | { |
| 8182 | expr.set_error (); |
| 8183 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 8184 | break; |
| 8185 | } |
| 8186 | { |
| 8187 | location_t close_loc = c_parser_peek_token (parser)->location; |
| 8188 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 8189 | "expected %<)%>" ); |
| 8190 | tree type = groktypename (t1, NULL, NULL); |
| 8191 | expr.value = objc_build_encode_expr (type); |
| 8192 | set_c_expr_source_range (&expr, loc, close_loc); |
| 8193 | } |
| 8194 | break; |
| 8195 | case RID_GENERIC: |
| 8196 | expr = c_parser_generic_selection (parser); |
| 8197 | break; |
| 8198 | case RID_CILK_SPAWN: |
| 8199 | c_parser_consume_token (parser); |
| 8200 | if (!flag_cilkplus) |
| 8201 | { |
| 8202 | error_at (loc, "-fcilkplus must be enabled to use " |
| 8203 | "%<_Cilk_spawn%>" ); |
| 8204 | expr = c_parser_cast_expression (parser, NULL); |
| 8205 | expr.set_error (); |
| 8206 | } |
| 8207 | else if (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN) |
| 8208 | { |
| 8209 | error_at (loc, "consecutive %<_Cilk_spawn%> keywords " |
| 8210 | "are not permitted" ); |
| 8211 | /* Now flush out all the _Cilk_spawns. */ |
| 8212 | while (c_parser_peek_token (parser)->keyword == RID_CILK_SPAWN) |
| 8213 | c_parser_consume_token (parser); |
| 8214 | expr = c_parser_cast_expression (parser, NULL); |
| 8215 | } |
| 8216 | else |
| 8217 | { |
| 8218 | expr = c_parser_cast_expression (parser, NULL); |
| 8219 | expr.value = build_cilk_spawn (loc, expr.value); |
| 8220 | } |
| 8221 | break; |
| 8222 | default: |
| 8223 | c_parser_error (parser, "expected expression" ); |
| 8224 | expr.set_error (); |
| 8225 | break; |
| 8226 | } |
| 8227 | break; |
| 8228 | case CPP_OPEN_SQUARE: |
| 8229 | if (c_dialect_objc ()) |
| 8230 | { |
| 8231 | tree receiver, args; |
| 8232 | c_parser_consume_token (parser); |
| 8233 | receiver = c_parser_objc_receiver (parser); |
| 8234 | args = c_parser_objc_message_args (parser); |
| 8235 | location_t close_loc = c_parser_peek_token (parser)->location; |
| 8236 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, |
| 8237 | "expected %<]%>" ); |
| 8238 | expr.value = objc_build_message_expr (receiver, args); |
| 8239 | set_c_expr_source_range (&expr, loc, close_loc); |
| 8240 | break; |
| 8241 | } |
| 8242 | /* Else fall through to report error. */ |
| 8243 | /* FALLTHRU */ |
| 8244 | default: |
| 8245 | c_parser_error (parser, "expected expression" ); |
| 8246 | expr.set_error (); |
| 8247 | break; |
| 8248 | } |
| 8249 | return c_parser_postfix_expression_after_primary |
| 8250 | (parser, EXPR_LOC_OR_LOC (expr.value, loc), expr); |
| 8251 | } |
| 8252 | |
| 8253 | /* Parse a postfix expression after a parenthesized type name: the |
| 8254 | brace-enclosed initializer of a compound literal, possibly followed |
| 8255 | by some postfix operators. This is separate because it is not |
| 8256 | possible to tell until after the type name whether a cast |
| 8257 | expression has a cast or a compound literal, or whether the operand |
| 8258 | of sizeof is a parenthesized type name or starts with a compound |
| 8259 | literal. TYPE_LOC is the location where TYPE_NAME starts--the |
| 8260 | location of the first token after the parentheses around the type |
| 8261 | name. */ |
| 8262 | |
| 8263 | static struct c_expr |
| 8264 | c_parser_postfix_expression_after_paren_type (c_parser *parser, |
| 8265 | struct c_type_name *type_name, |
| 8266 | location_t type_loc) |
| 8267 | { |
| 8268 | tree type; |
| 8269 | struct c_expr init; |
| 8270 | bool non_const; |
| 8271 | struct c_expr expr; |
| 8272 | location_t start_loc; |
| 8273 | tree type_expr = NULL_TREE; |
| 8274 | bool type_expr_const = true; |
| 8275 | check_compound_literal_type (type_loc, type_name); |
| 8276 | rich_location richloc (line_table, type_loc); |
| 8277 | start_init (NULL_TREE, NULL, 0, &richloc); |
| 8278 | type = groktypename (type_name, &type_expr, &type_expr_const); |
| 8279 | start_loc = c_parser_peek_token (parser)->location; |
| 8280 | if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type)) |
| 8281 | { |
| 8282 | error_at (type_loc, "compound literal has variable size" ); |
| 8283 | type = error_mark_node; |
| 8284 | } |
| 8285 | init = c_parser_braced_init (parser, type, false, NULL); |
| 8286 | finish_init (); |
| 8287 | maybe_warn_string_init (type_loc, type, init); |
| 8288 | |
| 8289 | if (type != error_mark_node |
| 8290 | && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type)) |
| 8291 | && current_function_decl) |
| 8292 | { |
| 8293 | error ("compound literal qualified by address-space qualifier" ); |
| 8294 | type = error_mark_node; |
| 8295 | } |
| 8296 | |
| 8297 | pedwarn_c90 (start_loc, OPT_Wpedantic, "ISO C90 forbids compound literals" ); |
| 8298 | non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR) |
| 8299 | ? CONSTRUCTOR_NON_CONST (init.value) |
| 8300 | : init.original_code == C_MAYBE_CONST_EXPR); |
| 8301 | non_const |= !type_expr_const; |
| 8302 | expr.value = build_compound_literal (start_loc, type, init.value, non_const); |
| 8303 | set_c_expr_source_range (&expr, init.src_range); |
| 8304 | expr.original_code = ERROR_MARK; |
| 8305 | expr.original_type = NULL; |
| 8306 | if (type != error_mark_node |
| 8307 | && expr.value != error_mark_node |
| 8308 | && type_expr) |
| 8309 | { |
| 8310 | if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR) |
| 8311 | { |
| 8312 | gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE); |
| 8313 | C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr; |
| 8314 | } |
| 8315 | else |
| 8316 | { |
| 8317 | gcc_assert (!non_const); |
| 8318 | expr.value = build2 (C_MAYBE_CONST_EXPR, type, |
| 8319 | type_expr, expr.value); |
| 8320 | } |
| 8321 | } |
| 8322 | return c_parser_postfix_expression_after_primary (parser, start_loc, expr); |
| 8323 | } |
| 8324 | |
| 8325 | /* Callback function for sizeof_pointer_memaccess_warning to compare |
| 8326 | types. */ |
| 8327 | |
| 8328 | static bool |
| 8329 | sizeof_ptr_memacc_comptypes (tree type1, tree type2) |
| 8330 | { |
| 8331 | return comptypes (type1, type2) == 1; |
| 8332 | } |
| 8333 | |
| 8334 | /* Parse a postfix expression after the initial primary or compound |
| 8335 | literal; that is, parse a series of postfix operators. |
| 8336 | |
| 8337 | EXPR_LOC is the location of the primary expression. */ |
| 8338 | |
| 8339 | static struct c_expr |
| 8340 | c_parser_postfix_expression_after_primary (c_parser *parser, |
| 8341 | location_t expr_loc, |
| 8342 | struct c_expr expr) |
| 8343 | { |
| 8344 | struct c_expr orig_expr; |
| 8345 | tree ident, idx; |
| 8346 | location_t sizeof_arg_loc[3], comp_loc; |
| 8347 | tree sizeof_arg[3]; |
| 8348 | unsigned int literal_zero_mask; |
| 8349 | unsigned int i; |
| 8350 | vec<tree, va_gc> *exprlist; |
| 8351 | vec<tree, va_gc> *origtypes = NULL; |
| 8352 | vec<location_t> arg_loc = vNULL; |
| 8353 | location_t start; |
| 8354 | location_t finish; |
| 8355 | |
| 8356 | while (true) |
| 8357 | { |
| 8358 | location_t op_loc = c_parser_peek_token (parser)->location; |
| 8359 | switch (c_parser_peek_token (parser)->type) |
| 8360 | { |
| 8361 | case CPP_OPEN_SQUARE: |
| 8362 | /* Array reference. */ |
| 8363 | c_parser_consume_token (parser); |
| 8364 | if (flag_cilkplus |
| 8365 | && c_parser_peek_token (parser)->type == CPP_COLON) |
| 8366 | /* If we are here, then we have something like this: |
| 8367 | Array [ : ] |
| 8368 | */ |
| 8369 | expr.value = c_parser_array_notation (expr_loc, parser, NULL_TREE, |
| 8370 | expr.value); |
| 8371 | else |
| 8372 | { |
| 8373 | idx = c_parser_expression (parser).value; |
| 8374 | /* Here we have 3 options: |
| 8375 | 1. Array [EXPR] -- Normal Array call. |
| 8376 | 2. Array [EXPR : EXPR] -- Array notation without stride. |
| 8377 | 3. Array [EXPR : EXPR : EXPR] -- Array notation with stride. |
| 8378 | |
| 8379 | For 1, we just handle it just like a normal array expression. |
| 8380 | For 2 and 3 we handle it like we handle array notations. The |
| 8381 | idx value we have above becomes the initial/start index. |
| 8382 | */ |
| 8383 | if (flag_cilkplus |
| 8384 | && c_parser_peek_token (parser)->type == CPP_COLON) |
| 8385 | expr.value = c_parser_array_notation (expr_loc, parser, idx, |
| 8386 | expr.value); |
| 8387 | else |
| 8388 | { |
| 8389 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, |
| 8390 | "expected %<]%>" ); |
| 8391 | start = expr.get_start (); |
| 8392 | finish = parser->tokens_buf[0].location; |
| 8393 | expr.value = build_array_ref (op_loc, expr.value, idx); |
| 8394 | set_c_expr_source_range (&expr, start, finish); |
| 8395 | } |
| 8396 | } |
| 8397 | expr.original_code = ERROR_MARK; |
| 8398 | expr.original_type = NULL; |
| 8399 | break; |
| 8400 | case CPP_OPEN_PAREN: |
| 8401 | /* Function call. */ |
| 8402 | c_parser_consume_token (parser); |
| 8403 | for (i = 0; i < 3; i++) |
| 8404 | { |
| 8405 | sizeof_arg[i] = NULL_TREE; |
| 8406 | sizeof_arg_loc[i] = UNKNOWN_LOCATION; |
| 8407 | } |
| 8408 | literal_zero_mask = 0; |
| 8409 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 8410 | exprlist = NULL; |
| 8411 | else |
| 8412 | exprlist = c_parser_expr_list (parser, true, false, &origtypes, |
| 8413 | sizeof_arg_loc, sizeof_arg, |
| 8414 | &arg_loc, &literal_zero_mask); |
| 8415 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 8416 | "expected %<)%>" ); |
| 8417 | orig_expr = expr; |
| 8418 | mark_exp_read (expr.value); |
| 8419 | if (warn_sizeof_pointer_memaccess) |
| 8420 | sizeof_pointer_memaccess_warning (sizeof_arg_loc, |
| 8421 | expr.value, exprlist, |
| 8422 | sizeof_arg, |
| 8423 | sizeof_ptr_memacc_comptypes); |
| 8424 | if (TREE_CODE (expr.value) == FUNCTION_DECL |
| 8425 | && DECL_BUILT_IN_CLASS (expr.value) == BUILT_IN_NORMAL |
| 8426 | && DECL_FUNCTION_CODE (expr.value) == BUILT_IN_MEMSET |
| 8427 | && vec_safe_length (exprlist) == 3) |
| 8428 | { |
| 8429 | tree arg0 = (*exprlist)[0]; |
| 8430 | tree arg2 = (*exprlist)[2]; |
| 8431 | warn_for_memset (expr_loc, arg0, arg2, literal_zero_mask); |
| 8432 | } |
| 8433 | |
| 8434 | start = expr.get_start (); |
| 8435 | finish = parser->tokens_buf[0].get_finish (); |
| 8436 | expr.value |
| 8437 | = c_build_function_call_vec (expr_loc, arg_loc, expr.value, |
| 8438 | exprlist, origtypes); |
| 8439 | set_c_expr_source_range (&expr, start, finish); |
| 8440 | |
| 8441 | expr.original_code = ERROR_MARK; |
| 8442 | if (TREE_CODE (expr.value) == INTEGER_CST |
| 8443 | && TREE_CODE (orig_expr.value) == FUNCTION_DECL |
| 8444 | && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL |
| 8445 | && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P) |
| 8446 | expr.original_code = C_MAYBE_CONST_EXPR; |
| 8447 | expr.original_type = NULL; |
| 8448 | if (exprlist) |
| 8449 | { |
| 8450 | release_tree_vector (exprlist); |
| 8451 | release_tree_vector (origtypes); |
| 8452 | } |
| 8453 | arg_loc.release (); |
| 8454 | break; |
| 8455 | case CPP_DOT: |
| 8456 | /* Structure element reference. */ |
| 8457 | c_parser_consume_token (parser); |
| 8458 | expr = default_function_array_conversion (expr_loc, expr); |
| 8459 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 8460 | { |
| 8461 | c_token *comp_tok = c_parser_peek_token (parser); |
| 8462 | ident = comp_tok->value; |
| 8463 | comp_loc = comp_tok->location; |
| 8464 | } |
| 8465 | else |
| 8466 | { |
| 8467 | c_parser_error (parser, "expected identifier" ); |
| 8468 | expr.set_error (); |
| 8469 | expr.original_code = ERROR_MARK; |
| 8470 | expr.original_type = NULL; |
| 8471 | return expr; |
| 8472 | } |
| 8473 | start = expr.get_start (); |
| 8474 | finish = c_parser_peek_token (parser)->get_finish (); |
| 8475 | c_parser_consume_token (parser); |
| 8476 | expr.value = build_component_ref (op_loc, expr.value, ident, |
| 8477 | comp_loc); |
| 8478 | set_c_expr_source_range (&expr, start, finish); |
| 8479 | expr.original_code = ERROR_MARK; |
| 8480 | if (TREE_CODE (expr.value) != COMPONENT_REF) |
| 8481 | expr.original_type = NULL; |
| 8482 | else |
| 8483 | { |
| 8484 | /* Remember the original type of a bitfield. */ |
| 8485 | tree field = TREE_OPERAND (expr.value, 1); |
| 8486 | if (TREE_CODE (field) != FIELD_DECL) |
| 8487 | expr.original_type = NULL; |
| 8488 | else |
| 8489 | expr.original_type = DECL_BIT_FIELD_TYPE (field); |
| 8490 | } |
| 8491 | break; |
| 8492 | case CPP_DEREF: |
| 8493 | /* Structure element reference. */ |
| 8494 | c_parser_consume_token (parser); |
| 8495 | expr = convert_lvalue_to_rvalue (expr_loc, expr, true, false); |
| 8496 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 8497 | { |
| 8498 | c_token *comp_tok = c_parser_peek_token (parser); |
| 8499 | ident = comp_tok->value; |
| 8500 | comp_loc = comp_tok->location; |
| 8501 | } |
| 8502 | else |
| 8503 | { |
| 8504 | c_parser_error (parser, "expected identifier" ); |
| 8505 | expr.set_error (); |
| 8506 | expr.original_code = ERROR_MARK; |
| 8507 | expr.original_type = NULL; |
| 8508 | return expr; |
| 8509 | } |
| 8510 | start = expr.get_start (); |
| 8511 | finish = c_parser_peek_token (parser)->get_finish (); |
| 8512 | c_parser_consume_token (parser); |
| 8513 | expr.value = build_component_ref (op_loc, |
| 8514 | build_indirect_ref (op_loc, |
| 8515 | expr.value, |
| 8516 | RO_ARROW), |
| 8517 | ident, comp_loc); |
| 8518 | set_c_expr_source_range (&expr, start, finish); |
| 8519 | expr.original_code = ERROR_MARK; |
| 8520 | if (TREE_CODE (expr.value) != COMPONENT_REF) |
| 8521 | expr.original_type = NULL; |
| 8522 | else |
| 8523 | { |
| 8524 | /* Remember the original type of a bitfield. */ |
| 8525 | tree field = TREE_OPERAND (expr.value, 1); |
| 8526 | if (TREE_CODE (field) != FIELD_DECL) |
| 8527 | expr.original_type = NULL; |
| 8528 | else |
| 8529 | expr.original_type = DECL_BIT_FIELD_TYPE (field); |
| 8530 | } |
| 8531 | break; |
| 8532 | case CPP_PLUS_PLUS: |
| 8533 | /* Postincrement. */ |
| 8534 | start = expr.get_start (); |
| 8535 | finish = c_parser_peek_token (parser)->get_finish (); |
| 8536 | c_parser_consume_token (parser); |
| 8537 | /* If the expressions have array notations, we expand them. */ |
| 8538 | if (flag_cilkplus |
| 8539 | && TREE_CODE (expr.value) == ARRAY_NOTATION_REF) |
| 8540 | expr = fix_array_notation_expr (expr_loc, POSTINCREMENT_EXPR, expr); |
| 8541 | else |
| 8542 | { |
| 8543 | expr = default_function_array_read_conversion (expr_loc, expr); |
| 8544 | expr.value = build_unary_op (op_loc, POSTINCREMENT_EXPR, |
| 8545 | expr.value, false); |
| 8546 | } |
| 8547 | set_c_expr_source_range (&expr, start, finish); |
| 8548 | expr.original_code = ERROR_MARK; |
| 8549 | expr.original_type = NULL; |
| 8550 | break; |
| 8551 | case CPP_MINUS_MINUS: |
| 8552 | /* Postdecrement. */ |
| 8553 | start = expr.get_start (); |
| 8554 | finish = c_parser_peek_token (parser)->get_finish (); |
| 8555 | c_parser_consume_token (parser); |
| 8556 | /* If the expressions have array notations, we expand them. */ |
| 8557 | if (flag_cilkplus |
| 8558 | && TREE_CODE (expr.value) == ARRAY_NOTATION_REF) |
| 8559 | expr = fix_array_notation_expr (expr_loc, POSTDECREMENT_EXPR, expr); |
| 8560 | else |
| 8561 | { |
| 8562 | expr = default_function_array_read_conversion (expr_loc, expr); |
| 8563 | expr.value = build_unary_op (op_loc, POSTDECREMENT_EXPR, |
| 8564 | expr.value, false); |
| 8565 | } |
| 8566 | set_c_expr_source_range (&expr, start, finish); |
| 8567 | expr.original_code = ERROR_MARK; |
| 8568 | expr.original_type = NULL; |
| 8569 | break; |
| 8570 | default: |
| 8571 | return expr; |
| 8572 | } |
| 8573 | } |
| 8574 | } |
| 8575 | |
| 8576 | /* Parse an expression (C90 6.3.17, C99 6.5.17, C11 6.5.17). |
| 8577 | |
| 8578 | expression: |
| 8579 | assignment-expression |
| 8580 | expression , assignment-expression |
| 8581 | */ |
| 8582 | |
| 8583 | static struct c_expr |
| 8584 | c_parser_expression (c_parser *parser) |
| 8585 | { |
| 8586 | location_t tloc = c_parser_peek_token (parser)->location; |
| 8587 | struct c_expr expr; |
| 8588 | expr = c_parser_expr_no_commas (parser, NULL); |
| 8589 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 8590 | expr = convert_lvalue_to_rvalue (tloc, expr, true, false); |
| 8591 | while (c_parser_next_token_is (parser, CPP_COMMA)) |
| 8592 | { |
| 8593 | struct c_expr next; |
| 8594 | tree lhsval; |
| 8595 | location_t loc = c_parser_peek_token (parser)->location; |
| 8596 | location_t expr_loc; |
| 8597 | c_parser_consume_token (parser); |
| 8598 | expr_loc = c_parser_peek_token (parser)->location; |
| 8599 | lhsval = expr.value; |
| 8600 | while (TREE_CODE (lhsval) == COMPOUND_EXPR) |
| 8601 | lhsval = TREE_OPERAND (lhsval, 1); |
| 8602 | if (DECL_P (lhsval) || handled_component_p (lhsval)) |
| 8603 | mark_exp_read (lhsval); |
| 8604 | next = c_parser_expr_no_commas (parser, NULL); |
| 8605 | next = convert_lvalue_to_rvalue (expr_loc, next, true, false); |
| 8606 | expr.value = build_compound_expr (loc, expr.value, next.value); |
| 8607 | expr.original_code = COMPOUND_EXPR; |
| 8608 | expr.original_type = next.original_type; |
| 8609 | } |
| 8610 | return expr; |
| 8611 | } |
| 8612 | |
| 8613 | /* Parse an expression and convert functions or arrays to pointers and |
| 8614 | lvalues to rvalues. */ |
| 8615 | |
| 8616 | static struct c_expr |
| 8617 | c_parser_expression_conv (c_parser *parser) |
| 8618 | { |
| 8619 | struct c_expr expr; |
| 8620 | location_t loc = c_parser_peek_token (parser)->location; |
| 8621 | expr = c_parser_expression (parser); |
| 8622 | expr = convert_lvalue_to_rvalue (loc, expr, true, false); |
| 8623 | return expr; |
| 8624 | } |
| 8625 | |
| 8626 | /* Helper function of c_parser_expr_list. Check if IDXth (0 based) |
| 8627 | argument is a literal zero alone and if so, set it in literal_zero_mask. */ |
| 8628 | |
| 8629 | static inline void |
| 8630 | c_parser_check_literal_zero (c_parser *parser, unsigned *literal_zero_mask, |
| 8631 | unsigned int idx) |
| 8632 | { |
| 8633 | if (idx >= HOST_BITS_PER_INT) |
| 8634 | return; |
| 8635 | |
| 8636 | c_token *tok = c_parser_peek_token (parser); |
| 8637 | switch (tok->type) |
| 8638 | { |
| 8639 | case CPP_NUMBER: |
| 8640 | case CPP_CHAR: |
| 8641 | case CPP_WCHAR: |
| 8642 | case CPP_CHAR16: |
| 8643 | case CPP_CHAR32: |
| 8644 | /* If a parameter is literal zero alone, remember it |
| 8645 | for -Wmemset-transposed-args warning. */ |
| 8646 | if (integer_zerop (tok->value) |
| 8647 | && !TREE_OVERFLOW (tok->value) |
| 8648 | && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA |
| 8649 | || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN)) |
| 8650 | *literal_zero_mask |= 1U << idx; |
| 8651 | default: |
| 8652 | break; |
| 8653 | } |
| 8654 | } |
| 8655 | |
| 8656 | /* Parse a non-empty list of expressions. If CONVERT_P, convert |
| 8657 | functions and arrays to pointers and lvalues to rvalues. If |
| 8658 | FOLD_P, fold the expressions. If LOCATIONS is non-NULL, save the |
| 8659 | locations of function arguments into this vector. |
| 8660 | |
| 8661 | nonempty-expr-list: |
| 8662 | assignment-expression |
| 8663 | nonempty-expr-list , assignment-expression |
| 8664 | */ |
| 8665 | |
| 8666 | static vec<tree, va_gc> * |
| 8667 | c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p, |
| 8668 | vec<tree, va_gc> **p_orig_types, |
| 8669 | location_t *sizeof_arg_loc, tree *sizeof_arg, |
| 8670 | vec<location_t> *locations, |
| 8671 | unsigned int *literal_zero_mask) |
| 8672 | { |
| 8673 | vec<tree, va_gc> *ret; |
| 8674 | vec<tree, va_gc> *orig_types; |
| 8675 | struct c_expr expr; |
| 8676 | location_t loc = c_parser_peek_token (parser)->location; |
| 8677 | location_t cur_sizeof_arg_loc = UNKNOWN_LOCATION; |
| 8678 | unsigned int idx = 0; |
| 8679 | |
| 8680 | ret = make_tree_vector (); |
| 8681 | if (p_orig_types == NULL) |
| 8682 | orig_types = NULL; |
| 8683 | else |
| 8684 | orig_types = make_tree_vector (); |
| 8685 | |
| 8686 | if (sizeof_arg != NULL |
| 8687 | && c_parser_next_token_is_keyword (parser, RID_SIZEOF)) |
| 8688 | cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location; |
| 8689 | if (literal_zero_mask) |
| 8690 | c_parser_check_literal_zero (parser, literal_zero_mask, 0); |
| 8691 | expr = c_parser_expr_no_commas (parser, NULL); |
| 8692 | if (convert_p) |
| 8693 | expr = convert_lvalue_to_rvalue (loc, expr, true, true); |
| 8694 | if (fold_p) |
| 8695 | expr.value = c_fully_fold (expr.value, false, NULL); |
| 8696 | ret->quick_push (expr.value); |
| 8697 | if (orig_types) |
| 8698 | orig_types->quick_push (expr.original_type); |
| 8699 | if (locations) |
| 8700 | locations->safe_push (loc); |
| 8701 | if (sizeof_arg != NULL |
| 8702 | && cur_sizeof_arg_loc != UNKNOWN_LOCATION |
| 8703 | && expr.original_code == SIZEOF_EXPR) |
| 8704 | { |
| 8705 | sizeof_arg[0] = c_last_sizeof_arg; |
| 8706 | sizeof_arg_loc[0] = cur_sizeof_arg_loc; |
| 8707 | } |
| 8708 | while (c_parser_next_token_is (parser, CPP_COMMA)) |
| 8709 | { |
| 8710 | c_parser_consume_token (parser); |
| 8711 | loc = c_parser_peek_token (parser)->location; |
| 8712 | if (sizeof_arg != NULL |
| 8713 | && c_parser_next_token_is_keyword (parser, RID_SIZEOF)) |
| 8714 | cur_sizeof_arg_loc = c_parser_peek_2nd_token (parser)->location; |
| 8715 | else |
| 8716 | cur_sizeof_arg_loc = UNKNOWN_LOCATION; |
| 8717 | if (literal_zero_mask) |
| 8718 | c_parser_check_literal_zero (parser, literal_zero_mask, idx + 1); |
| 8719 | expr = c_parser_expr_no_commas (parser, NULL); |
| 8720 | if (convert_p) |
| 8721 | expr = convert_lvalue_to_rvalue (loc, expr, true, true); |
| 8722 | if (fold_p) |
| 8723 | expr.value = c_fully_fold (expr.value, false, NULL); |
| 8724 | vec_safe_push (ret, expr.value); |
| 8725 | if (orig_types) |
| 8726 | vec_safe_push (orig_types, expr.original_type); |
| 8727 | if (locations) |
| 8728 | locations->safe_push (loc); |
| 8729 | if (++idx < 3 |
| 8730 | && sizeof_arg != NULL |
| 8731 | && cur_sizeof_arg_loc != UNKNOWN_LOCATION |
| 8732 | && expr.original_code == SIZEOF_EXPR) |
| 8733 | { |
| 8734 | sizeof_arg[idx] = c_last_sizeof_arg; |
| 8735 | sizeof_arg_loc[idx] = cur_sizeof_arg_loc; |
| 8736 | } |
| 8737 | } |
| 8738 | if (orig_types) |
| 8739 | *p_orig_types = orig_types; |
| 8740 | return ret; |
| 8741 | } |
| 8742 | |
| 8743 | /* Parse Objective-C-specific constructs. */ |
| 8744 | |
| 8745 | /* Parse an objc-class-definition. |
| 8746 | |
| 8747 | objc-class-definition: |
| 8748 | @interface identifier objc-superclass[opt] objc-protocol-refs[opt] |
| 8749 | objc-class-instance-variables[opt] objc-methodprotolist @end |
| 8750 | @implementation identifier objc-superclass[opt] |
| 8751 | objc-class-instance-variables[opt] |
| 8752 | @interface identifier ( identifier ) objc-protocol-refs[opt] |
| 8753 | objc-methodprotolist @end |
| 8754 | @interface identifier ( ) objc-protocol-refs[opt] |
| 8755 | objc-methodprotolist @end |
| 8756 | @implementation identifier ( identifier ) |
| 8757 | |
| 8758 | objc-superclass: |
| 8759 | : identifier |
| 8760 | |
| 8761 | "@interface identifier (" must start "@interface identifier ( |
| 8762 | identifier ) ...": objc-methodprotolist in the first production may |
| 8763 | not start with a parenthesized identifier as a declarator of a data |
| 8764 | definition with no declaration specifiers if the objc-superclass, |
| 8765 | objc-protocol-refs and objc-class-instance-variables are omitted. */ |
| 8766 | |
| 8767 | static void |
| 8768 | c_parser_objc_class_definition (c_parser *parser, tree attributes) |
| 8769 | { |
| 8770 | bool iface_p; |
| 8771 | tree id1; |
| 8772 | tree superclass; |
| 8773 | if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE)) |
| 8774 | iface_p = true; |
| 8775 | else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION)) |
| 8776 | iface_p = false; |
| 8777 | else |
| 8778 | gcc_unreachable (); |
| 8779 | |
| 8780 | c_parser_consume_token (parser); |
| 8781 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 8782 | { |
| 8783 | c_parser_error (parser, "expected identifier" ); |
| 8784 | return; |
| 8785 | } |
| 8786 | id1 = c_parser_peek_token (parser)->value; |
| 8787 | c_parser_consume_token (parser); |
| 8788 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 8789 | { |
| 8790 | /* We have a category or class extension. */ |
| 8791 | tree id2; |
| 8792 | tree proto = NULL_TREE; |
| 8793 | c_parser_consume_token (parser); |
| 8794 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 8795 | { |
| 8796 | if (iface_p && c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 8797 | { |
| 8798 | /* We have a class extension. */ |
| 8799 | id2 = NULL_TREE; |
| 8800 | } |
| 8801 | else |
| 8802 | { |
| 8803 | c_parser_error (parser, "expected identifier or %<)%>" ); |
| 8804 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 8805 | return; |
| 8806 | } |
| 8807 | } |
| 8808 | else |
| 8809 | { |
| 8810 | id2 = c_parser_peek_token (parser)->value; |
| 8811 | c_parser_consume_token (parser); |
| 8812 | } |
| 8813 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 8814 | if (!iface_p) |
| 8815 | { |
| 8816 | objc_start_category_implementation (id1, id2); |
| 8817 | return; |
| 8818 | } |
| 8819 | if (c_parser_next_token_is (parser, CPP_LESS)) |
| 8820 | proto = c_parser_objc_protocol_refs (parser); |
| 8821 | objc_start_category_interface (id1, id2, proto, attributes); |
| 8822 | c_parser_objc_methodprotolist (parser); |
| 8823 | c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>" ); |
| 8824 | objc_finish_interface (); |
| 8825 | return; |
| 8826 | } |
| 8827 | if (c_parser_next_token_is (parser, CPP_COLON)) |
| 8828 | { |
| 8829 | c_parser_consume_token (parser); |
| 8830 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 8831 | { |
| 8832 | c_parser_error (parser, "expected identifier" ); |
| 8833 | return; |
| 8834 | } |
| 8835 | superclass = c_parser_peek_token (parser)->value; |
| 8836 | c_parser_consume_token (parser); |
| 8837 | } |
| 8838 | else |
| 8839 | superclass = NULL_TREE; |
| 8840 | if (iface_p) |
| 8841 | { |
| 8842 | tree proto = NULL_TREE; |
| 8843 | if (c_parser_next_token_is (parser, CPP_LESS)) |
| 8844 | proto = c_parser_objc_protocol_refs (parser); |
| 8845 | objc_start_class_interface (id1, superclass, proto, attributes); |
| 8846 | } |
| 8847 | else |
| 8848 | objc_start_class_implementation (id1, superclass); |
| 8849 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 8850 | c_parser_objc_class_instance_variables (parser); |
| 8851 | if (iface_p) |
| 8852 | { |
| 8853 | objc_continue_interface (); |
| 8854 | c_parser_objc_methodprotolist (parser); |
| 8855 | c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>" ); |
| 8856 | objc_finish_interface (); |
| 8857 | } |
| 8858 | else |
| 8859 | { |
| 8860 | objc_continue_implementation (); |
| 8861 | return; |
| 8862 | } |
| 8863 | } |
| 8864 | |
| 8865 | /* Parse objc-class-instance-variables. |
| 8866 | |
| 8867 | objc-class-instance-variables: |
| 8868 | { objc-instance-variable-decl-list[opt] } |
| 8869 | |
| 8870 | objc-instance-variable-decl-list: |
| 8871 | objc-visibility-spec |
| 8872 | objc-instance-variable-decl ; |
| 8873 | ; |
| 8874 | objc-instance-variable-decl-list objc-visibility-spec |
| 8875 | objc-instance-variable-decl-list objc-instance-variable-decl ; |
| 8876 | objc-instance-variable-decl-list ; |
| 8877 | |
| 8878 | objc-visibility-spec: |
| 8879 | @private |
| 8880 | @protected |
| 8881 | @public |
| 8882 | |
| 8883 | objc-instance-variable-decl: |
| 8884 | struct-declaration |
| 8885 | */ |
| 8886 | |
| 8887 | static void |
| 8888 | c_parser_objc_class_instance_variables (c_parser *parser) |
| 8889 | { |
| 8890 | gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE)); |
| 8891 | c_parser_consume_token (parser); |
| 8892 | while (c_parser_next_token_is_not (parser, CPP_EOF)) |
| 8893 | { |
| 8894 | tree decls; |
| 8895 | /* Parse any stray semicolon. */ |
| 8896 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 8897 | { |
| 8898 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
| 8899 | "extra semicolon" ); |
| 8900 | c_parser_consume_token (parser); |
| 8901 | continue; |
| 8902 | } |
| 8903 | /* Stop if at the end of the instance variables. */ |
| 8904 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 8905 | { |
| 8906 | c_parser_consume_token (parser); |
| 8907 | break; |
| 8908 | } |
| 8909 | /* Parse any objc-visibility-spec. */ |
| 8910 | if (c_parser_next_token_is_keyword (parser, RID_AT_PRIVATE)) |
| 8911 | { |
| 8912 | c_parser_consume_token (parser); |
| 8913 | objc_set_visibility (OBJC_IVAR_VIS_PRIVATE); |
| 8914 | continue; |
| 8915 | } |
| 8916 | else if (c_parser_next_token_is_keyword (parser, RID_AT_PROTECTED)) |
| 8917 | { |
| 8918 | c_parser_consume_token (parser); |
| 8919 | objc_set_visibility (OBJC_IVAR_VIS_PROTECTED); |
| 8920 | continue; |
| 8921 | } |
| 8922 | else if (c_parser_next_token_is_keyword (parser, RID_AT_PUBLIC)) |
| 8923 | { |
| 8924 | c_parser_consume_token (parser); |
| 8925 | objc_set_visibility (OBJC_IVAR_VIS_PUBLIC); |
| 8926 | continue; |
| 8927 | } |
| 8928 | else if (c_parser_next_token_is_keyword (parser, RID_AT_PACKAGE)) |
| 8929 | { |
| 8930 | c_parser_consume_token (parser); |
| 8931 | objc_set_visibility (OBJC_IVAR_VIS_PACKAGE); |
| 8932 | continue; |
| 8933 | } |
| 8934 | else if (c_parser_next_token_is (parser, CPP_PRAGMA)) |
| 8935 | { |
| 8936 | c_parser_pragma (parser, pragma_external, NULL); |
| 8937 | continue; |
| 8938 | } |
| 8939 | |
| 8940 | /* Parse some comma-separated declarations. */ |
| 8941 | decls = c_parser_struct_declaration (parser); |
| 8942 | if (decls == NULL) |
| 8943 | { |
| 8944 | /* There is a syntax error. We want to skip the offending |
| 8945 | tokens up to the next ';' (included) or '}' |
| 8946 | (excluded). */ |
| 8947 | |
| 8948 | /* First, skip manually a ')' or ']'. This is because they |
| 8949 | reduce the nesting level, so c_parser_skip_until_found() |
| 8950 | wouldn't be able to skip past them. */ |
| 8951 | c_token *token = c_parser_peek_token (parser); |
| 8952 | if (token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE) |
| 8953 | c_parser_consume_token (parser); |
| 8954 | |
| 8955 | /* Then, do the standard skipping. */ |
| 8956 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
| 8957 | |
| 8958 | /* We hopefully recovered. Start normal parsing again. */ |
| 8959 | parser->error = false; |
| 8960 | continue; |
| 8961 | } |
| 8962 | else |
| 8963 | { |
| 8964 | /* Comma-separated instance variables are chained together |
| 8965 | in reverse order; add them one by one. */ |
| 8966 | tree ivar = nreverse (decls); |
| 8967 | for (; ivar; ivar = DECL_CHAIN (ivar)) |
| 8968 | objc_add_instance_variable (copy_node (ivar)); |
| 8969 | } |
| 8970 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>" ); |
| 8971 | } |
| 8972 | } |
| 8973 | |
| 8974 | /* Parse an objc-class-declaration. |
| 8975 | |
| 8976 | objc-class-declaration: |
| 8977 | @class identifier-list ; |
| 8978 | */ |
| 8979 | |
| 8980 | static void |
| 8981 | c_parser_objc_class_declaration (c_parser *parser) |
| 8982 | { |
| 8983 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_CLASS)); |
| 8984 | c_parser_consume_token (parser); |
| 8985 | /* Any identifiers, including those declared as type names, are OK |
| 8986 | here. */ |
| 8987 | while (true) |
| 8988 | { |
| 8989 | tree id; |
| 8990 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 8991 | { |
| 8992 | c_parser_error (parser, "expected identifier" ); |
| 8993 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
| 8994 | parser->error = false; |
| 8995 | return; |
| 8996 | } |
| 8997 | id = c_parser_peek_token (parser)->value; |
| 8998 | objc_declare_class (id); |
| 8999 | c_parser_consume_token (parser); |
| 9000 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 9001 | c_parser_consume_token (parser); |
| 9002 | else |
| 9003 | break; |
| 9004 | } |
| 9005 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>" ); |
| 9006 | } |
| 9007 | |
| 9008 | /* Parse an objc-alias-declaration. |
| 9009 | |
| 9010 | objc-alias-declaration: |
| 9011 | @compatibility_alias identifier identifier ; |
| 9012 | */ |
| 9013 | |
| 9014 | static void |
| 9015 | c_parser_objc_alias_declaration (c_parser *parser) |
| 9016 | { |
| 9017 | tree id1, id2; |
| 9018 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS)); |
| 9019 | c_parser_consume_token (parser); |
| 9020 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 9021 | { |
| 9022 | c_parser_error (parser, "expected identifier" ); |
| 9023 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
| 9024 | return; |
| 9025 | } |
| 9026 | id1 = c_parser_peek_token (parser)->value; |
| 9027 | c_parser_consume_token (parser); |
| 9028 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 9029 | { |
| 9030 | c_parser_error (parser, "expected identifier" ); |
| 9031 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
| 9032 | return; |
| 9033 | } |
| 9034 | id2 = c_parser_peek_token (parser)->value; |
| 9035 | c_parser_consume_token (parser); |
| 9036 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>" ); |
| 9037 | objc_declare_alias (id1, id2); |
| 9038 | } |
| 9039 | |
| 9040 | /* Parse an objc-protocol-definition. |
| 9041 | |
| 9042 | objc-protocol-definition: |
| 9043 | @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end |
| 9044 | @protocol identifier-list ; |
| 9045 | |
| 9046 | "@protocol identifier ;" should be resolved as "@protocol |
| 9047 | identifier-list ;": objc-methodprotolist may not start with a |
| 9048 | semicolon in the first alternative if objc-protocol-refs are |
| 9049 | omitted. */ |
| 9050 | |
| 9051 | static void |
| 9052 | c_parser_objc_protocol_definition (c_parser *parser, tree attributes) |
| 9053 | { |
| 9054 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL)); |
| 9055 | |
| 9056 | c_parser_consume_token (parser); |
| 9057 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 9058 | { |
| 9059 | c_parser_error (parser, "expected identifier" ); |
| 9060 | return; |
| 9061 | } |
| 9062 | if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA |
| 9063 | || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON) |
| 9064 | { |
| 9065 | /* Any identifiers, including those declared as type names, are |
| 9066 | OK here. */ |
| 9067 | while (true) |
| 9068 | { |
| 9069 | tree id; |
| 9070 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 9071 | { |
| 9072 | c_parser_error (parser, "expected identifier" ); |
| 9073 | break; |
| 9074 | } |
| 9075 | id = c_parser_peek_token (parser)->value; |
| 9076 | objc_declare_protocol (id, attributes); |
| 9077 | c_parser_consume_token (parser); |
| 9078 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 9079 | c_parser_consume_token (parser); |
| 9080 | else |
| 9081 | break; |
| 9082 | } |
| 9083 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>" ); |
| 9084 | } |
| 9085 | else |
| 9086 | { |
| 9087 | tree id = c_parser_peek_token (parser)->value; |
| 9088 | tree proto = NULL_TREE; |
| 9089 | c_parser_consume_token (parser); |
| 9090 | if (c_parser_next_token_is (parser, CPP_LESS)) |
| 9091 | proto = c_parser_objc_protocol_refs (parser); |
| 9092 | parser->objc_pq_context = true; |
| 9093 | objc_start_protocol (id, proto, attributes); |
| 9094 | c_parser_objc_methodprotolist (parser); |
| 9095 | c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>" ); |
| 9096 | parser->objc_pq_context = false; |
| 9097 | objc_finish_interface (); |
| 9098 | } |
| 9099 | } |
| 9100 | |
| 9101 | /* Parse an objc-method-type. |
| 9102 | |
| 9103 | objc-method-type: |
| 9104 | + |
| 9105 | - |
| 9106 | |
| 9107 | Return true if it is a class method (+) and false if it is |
| 9108 | an instance method (-). |
| 9109 | */ |
| 9110 | static inline bool |
| 9111 | c_parser_objc_method_type (c_parser *parser) |
| 9112 | { |
| 9113 | switch (c_parser_peek_token (parser)->type) |
| 9114 | { |
| 9115 | case CPP_PLUS: |
| 9116 | c_parser_consume_token (parser); |
| 9117 | return true; |
| 9118 | case CPP_MINUS: |
| 9119 | c_parser_consume_token (parser); |
| 9120 | return false; |
| 9121 | default: |
| 9122 | gcc_unreachable (); |
| 9123 | } |
| 9124 | } |
| 9125 | |
| 9126 | /* Parse an objc-method-definition. |
| 9127 | |
| 9128 | objc-method-definition: |
| 9129 | objc-method-type objc-method-decl ;[opt] compound-statement |
| 9130 | */ |
| 9131 | |
| 9132 | static void |
| 9133 | c_parser_objc_method_definition (c_parser *parser) |
| 9134 | { |
| 9135 | bool is_class_method = c_parser_objc_method_type (parser); |
| 9136 | tree decl, attributes = NULL_TREE, expr = NULL_TREE; |
| 9137 | parser->objc_pq_context = true; |
| 9138 | decl = c_parser_objc_method_decl (parser, is_class_method, &attributes, |
| 9139 | &expr); |
| 9140 | if (decl == error_mark_node) |
| 9141 | return; /* Bail here. */ |
| 9142 | |
| 9143 | if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 9144 | { |
| 9145 | c_parser_consume_token (parser); |
| 9146 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
| 9147 | "extra semicolon in method definition specified" ); |
| 9148 | } |
| 9149 | |
| 9150 | if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 9151 | { |
| 9152 | c_parser_error (parser, "expected %<{%>" ); |
| 9153 | return; |
| 9154 | } |
| 9155 | |
| 9156 | parser->objc_pq_context = false; |
| 9157 | if (objc_start_method_definition (is_class_method, decl, attributes, expr)) |
| 9158 | { |
| 9159 | add_stmt (c_parser_compound_statement (parser)); |
| 9160 | objc_finish_method_definition (current_function_decl); |
| 9161 | } |
| 9162 | else |
| 9163 | { |
| 9164 | /* This code is executed when we find a method definition |
| 9165 | outside of an @implementation context (or invalid for other |
| 9166 | reasons). Parse the method (to keep going) but do not emit |
| 9167 | any code. |
| 9168 | */ |
| 9169 | c_parser_compound_statement (parser); |
| 9170 | } |
| 9171 | } |
| 9172 | |
| 9173 | /* Parse an objc-methodprotolist. |
| 9174 | |
| 9175 | objc-methodprotolist: |
| 9176 | empty |
| 9177 | objc-methodprotolist objc-methodproto |
| 9178 | objc-methodprotolist declaration |
| 9179 | objc-methodprotolist ; |
| 9180 | @optional |
| 9181 | @required |
| 9182 | |
| 9183 | The declaration is a data definition, which may be missing |
| 9184 | declaration specifiers under the same rules and diagnostics as |
| 9185 | other data definitions outside functions, and the stray semicolon |
| 9186 | is diagnosed the same way as a stray semicolon outside a |
| 9187 | function. */ |
| 9188 | |
| 9189 | static void |
| 9190 | c_parser_objc_methodprotolist (c_parser *parser) |
| 9191 | { |
| 9192 | while (true) |
| 9193 | { |
| 9194 | /* The list is terminated by @end. */ |
| 9195 | switch (c_parser_peek_token (parser)->type) |
| 9196 | { |
| 9197 | case CPP_SEMICOLON: |
| 9198 | pedwarn (c_parser_peek_token (parser)->location, OPT_Wpedantic, |
| 9199 | "ISO C does not allow extra %<;%> outside of a function" ); |
| 9200 | c_parser_consume_token (parser); |
| 9201 | break; |
| 9202 | case CPP_PLUS: |
| 9203 | case CPP_MINUS: |
| 9204 | c_parser_objc_methodproto (parser); |
| 9205 | break; |
| 9206 | case CPP_PRAGMA: |
| 9207 | c_parser_pragma (parser, pragma_external, NULL); |
| 9208 | break; |
| 9209 | case CPP_EOF: |
| 9210 | return; |
| 9211 | default: |
| 9212 | if (c_parser_next_token_is_keyword (parser, RID_AT_END)) |
| 9213 | return; |
| 9214 | else if (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY)) |
| 9215 | c_parser_objc_at_property_declaration (parser); |
| 9216 | else if (c_parser_next_token_is_keyword (parser, RID_AT_OPTIONAL)) |
| 9217 | { |
| 9218 | objc_set_method_opt (true); |
| 9219 | c_parser_consume_token (parser); |
| 9220 | } |
| 9221 | else if (c_parser_next_token_is_keyword (parser, RID_AT_REQUIRED)) |
| 9222 | { |
| 9223 | objc_set_method_opt (false); |
| 9224 | c_parser_consume_token (parser); |
| 9225 | } |
| 9226 | else |
| 9227 | c_parser_declaration_or_fndef (parser, false, false, true, |
| 9228 | false, true, NULL, vNULL); |
| 9229 | break; |
| 9230 | } |
| 9231 | } |
| 9232 | } |
| 9233 | |
| 9234 | /* Parse an objc-methodproto. |
| 9235 | |
| 9236 | objc-methodproto: |
| 9237 | objc-method-type objc-method-decl ; |
| 9238 | */ |
| 9239 | |
| 9240 | static void |
| 9241 | c_parser_objc_methodproto (c_parser *parser) |
| 9242 | { |
| 9243 | bool is_class_method = c_parser_objc_method_type (parser); |
| 9244 | tree decl, attributes = NULL_TREE; |
| 9245 | |
| 9246 | /* Remember protocol qualifiers in prototypes. */ |
| 9247 | parser->objc_pq_context = true; |
| 9248 | decl = c_parser_objc_method_decl (parser, is_class_method, &attributes, |
| 9249 | NULL); |
| 9250 | /* Forget protocol qualifiers now. */ |
| 9251 | parser->objc_pq_context = false; |
| 9252 | |
| 9253 | /* Do not allow the presence of attributes to hide an erroneous |
| 9254 | method implementation in the interface section. */ |
| 9255 | if (!c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 9256 | { |
| 9257 | c_parser_error (parser, "expected %<;%>" ); |
| 9258 | return; |
| 9259 | } |
| 9260 | |
| 9261 | if (decl != error_mark_node) |
| 9262 | objc_add_method_declaration (is_class_method, decl, attributes); |
| 9263 | |
| 9264 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>" ); |
| 9265 | } |
| 9266 | |
| 9267 | /* If we are at a position that method attributes may be present, check that |
| 9268 | there are not any parsed already (a syntax error) and then collect any |
| 9269 | specified at the current location. Finally, if new attributes were present, |
| 9270 | check that the next token is legal ( ';' for decls and '{' for defs). */ |
| 9271 | |
| 9272 | static bool |
| 9273 | c_parser_objc_maybe_method_attributes (c_parser* parser, tree* attributes) |
| 9274 | { |
| 9275 | bool bad = false; |
| 9276 | if (*attributes) |
| 9277 | { |
| 9278 | c_parser_error (parser, |
| 9279 | "method attributes must be specified at the end only" ); |
| 9280 | *attributes = NULL_TREE; |
| 9281 | bad = true; |
| 9282 | } |
| 9283 | |
| 9284 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 9285 | *attributes = c_parser_attributes (parser); |
| 9286 | |
| 9287 | /* If there were no attributes here, just report any earlier error. */ |
| 9288 | if (*attributes == NULL_TREE || bad) |
| 9289 | return bad; |
| 9290 | |
| 9291 | /* If the attributes are followed by a ; or {, then just report any earlier |
| 9292 | error. */ |
| 9293 | if (c_parser_next_token_is (parser, CPP_SEMICOLON) |
| 9294 | || c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 9295 | return bad; |
| 9296 | |
| 9297 | /* We've got attributes, but not at the end. */ |
| 9298 | c_parser_error (parser, |
| 9299 | "expected %<;%> or %<{%> after method attribute definition" ); |
| 9300 | return true; |
| 9301 | } |
| 9302 | |
| 9303 | /* Parse an objc-method-decl. |
| 9304 | |
| 9305 | objc-method-decl: |
| 9306 | ( objc-type-name ) objc-selector |
| 9307 | objc-selector |
| 9308 | ( objc-type-name ) objc-keyword-selector objc-optparmlist |
| 9309 | objc-keyword-selector objc-optparmlist |
| 9310 | attributes |
| 9311 | |
| 9312 | objc-keyword-selector: |
| 9313 | objc-keyword-decl |
| 9314 | objc-keyword-selector objc-keyword-decl |
| 9315 | |
| 9316 | objc-keyword-decl: |
| 9317 | objc-selector : ( objc-type-name ) identifier |
| 9318 | objc-selector : identifier |
| 9319 | : ( objc-type-name ) identifier |
| 9320 | : identifier |
| 9321 | |
| 9322 | objc-optparmlist: |
| 9323 | objc-optparms objc-optellipsis |
| 9324 | |
| 9325 | objc-optparms: |
| 9326 | empty |
| 9327 | objc-opt-parms , parameter-declaration |
| 9328 | |
| 9329 | objc-optellipsis: |
| 9330 | empty |
| 9331 | , ... |
| 9332 | */ |
| 9333 | |
| 9334 | static tree |
| 9335 | c_parser_objc_method_decl (c_parser *parser, bool is_class_method, |
| 9336 | tree *attributes, tree *expr) |
| 9337 | { |
| 9338 | tree type = NULL_TREE; |
| 9339 | tree sel; |
| 9340 | tree parms = NULL_TREE; |
| 9341 | bool ellipsis = false; |
| 9342 | bool attr_err = false; |
| 9343 | |
| 9344 | *attributes = NULL_TREE; |
| 9345 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 9346 | { |
| 9347 | c_parser_consume_token (parser); |
| 9348 | type = c_parser_objc_type_name (parser); |
| 9349 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 9350 | } |
| 9351 | sel = c_parser_objc_selector (parser); |
| 9352 | /* If there is no selector, or a colon follows, we have an |
| 9353 | objc-keyword-selector. If there is a selector, and a colon does |
| 9354 | not follow, that selector ends the objc-method-decl. */ |
| 9355 | if (!sel || c_parser_next_token_is (parser, CPP_COLON)) |
| 9356 | { |
| 9357 | tree tsel = sel; |
| 9358 | tree list = NULL_TREE; |
| 9359 | while (true) |
| 9360 | { |
| 9361 | tree atype = NULL_TREE, id, keyworddecl; |
| 9362 | tree param_attr = NULL_TREE; |
| 9363 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>" )) |
| 9364 | break; |
| 9365 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 9366 | { |
| 9367 | c_parser_consume_token (parser); |
| 9368 | atype = c_parser_objc_type_name (parser); |
| 9369 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 9370 | "expected %<)%>" ); |
| 9371 | } |
| 9372 | /* New ObjC allows attributes on method parameters. */ |
| 9373 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 9374 | param_attr = c_parser_attributes (parser); |
| 9375 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 9376 | { |
| 9377 | c_parser_error (parser, "expected identifier" ); |
| 9378 | return error_mark_node; |
| 9379 | } |
| 9380 | id = c_parser_peek_token (parser)->value; |
| 9381 | c_parser_consume_token (parser); |
| 9382 | keyworddecl = objc_build_keyword_decl (tsel, atype, id, param_attr); |
| 9383 | list = chainon (list, keyworddecl); |
| 9384 | tsel = c_parser_objc_selector (parser); |
| 9385 | if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON)) |
| 9386 | break; |
| 9387 | } |
| 9388 | |
| 9389 | attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ; |
| 9390 | |
| 9391 | /* Parse the optional parameter list. Optional Objective-C |
| 9392 | method parameters follow the C syntax, and may include '...' |
| 9393 | to denote a variable number of arguments. */ |
| 9394 | parms = make_node (TREE_LIST); |
| 9395 | while (c_parser_next_token_is (parser, CPP_COMMA)) |
| 9396 | { |
| 9397 | struct c_parm *parm; |
| 9398 | c_parser_consume_token (parser); |
| 9399 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) |
| 9400 | { |
| 9401 | ellipsis = true; |
| 9402 | c_parser_consume_token (parser); |
| 9403 | attr_err |= c_parser_objc_maybe_method_attributes |
| 9404 | (parser, attributes) ; |
| 9405 | break; |
| 9406 | } |
| 9407 | parm = c_parser_parameter_declaration (parser, NULL_TREE); |
| 9408 | if (parm == NULL) |
| 9409 | break; |
| 9410 | parms = chainon (parms, |
| 9411 | build_tree_list (NULL_TREE, grokparm (parm, expr))); |
| 9412 | } |
| 9413 | sel = list; |
| 9414 | } |
| 9415 | else |
| 9416 | attr_err |= c_parser_objc_maybe_method_attributes (parser, attributes) ; |
| 9417 | |
| 9418 | if (sel == NULL) |
| 9419 | { |
| 9420 | c_parser_error (parser, "objective-c method declaration is expected" ); |
| 9421 | return error_mark_node; |
| 9422 | } |
| 9423 | |
| 9424 | if (attr_err) |
| 9425 | return error_mark_node; |
| 9426 | |
| 9427 | return objc_build_method_signature (is_class_method, type, sel, parms, ellipsis); |
| 9428 | } |
| 9429 | |
| 9430 | /* Parse an objc-type-name. |
| 9431 | |
| 9432 | objc-type-name: |
| 9433 | objc-type-qualifiers[opt] type-name |
| 9434 | objc-type-qualifiers[opt] |
| 9435 | |
| 9436 | objc-type-qualifiers: |
| 9437 | objc-type-qualifier |
| 9438 | objc-type-qualifiers objc-type-qualifier |
| 9439 | |
| 9440 | objc-type-qualifier: one of |
| 9441 | in out inout bycopy byref oneway |
| 9442 | */ |
| 9443 | |
| 9444 | static tree |
| 9445 | c_parser_objc_type_name (c_parser *parser) |
| 9446 | { |
| 9447 | tree quals = NULL_TREE; |
| 9448 | struct c_type_name *type_name = NULL; |
| 9449 | tree type = NULL_TREE; |
| 9450 | while (true) |
| 9451 | { |
| 9452 | c_token *token = c_parser_peek_token (parser); |
| 9453 | if (token->type == CPP_KEYWORD |
| 9454 | && (token->keyword == RID_IN |
| 9455 | || token->keyword == RID_OUT |
| 9456 | || token->keyword == RID_INOUT |
| 9457 | || token->keyword == RID_BYCOPY |
| 9458 | || token->keyword == RID_BYREF |
| 9459 | || token->keyword == RID_ONEWAY)) |
| 9460 | { |
| 9461 | quals = chainon (build_tree_list (NULL_TREE, token->value), quals); |
| 9462 | c_parser_consume_token (parser); |
| 9463 | } |
| 9464 | else |
| 9465 | break; |
| 9466 | } |
| 9467 | if (c_parser_next_tokens_start_typename (parser, cla_prefer_type)) |
| 9468 | type_name = c_parser_type_name (parser); |
| 9469 | if (type_name) |
| 9470 | type = groktypename (type_name, NULL, NULL); |
| 9471 | |
| 9472 | /* If the type is unknown, and error has already been produced and |
| 9473 | we need to recover from the error. In that case, use NULL_TREE |
| 9474 | for the type, as if no type had been specified; this will use the |
| 9475 | default type ('id') which is good for error recovery. */ |
| 9476 | if (type == error_mark_node) |
| 9477 | type = NULL_TREE; |
| 9478 | |
| 9479 | return build_tree_list (quals, type); |
| 9480 | } |
| 9481 | |
| 9482 | /* Parse objc-protocol-refs. |
| 9483 | |
| 9484 | objc-protocol-refs: |
| 9485 | < identifier-list > |
| 9486 | */ |
| 9487 | |
| 9488 | static tree |
| 9489 | c_parser_objc_protocol_refs (c_parser *parser) |
| 9490 | { |
| 9491 | tree list = NULL_TREE; |
| 9492 | gcc_assert (c_parser_next_token_is (parser, CPP_LESS)); |
| 9493 | c_parser_consume_token (parser); |
| 9494 | /* Any identifiers, including those declared as type names, are OK |
| 9495 | here. */ |
| 9496 | while (true) |
| 9497 | { |
| 9498 | tree id; |
| 9499 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 9500 | { |
| 9501 | c_parser_error (parser, "expected identifier" ); |
| 9502 | break; |
| 9503 | } |
| 9504 | id = c_parser_peek_token (parser)->value; |
| 9505 | list = chainon (list, build_tree_list (NULL_TREE, id)); |
| 9506 | c_parser_consume_token (parser); |
| 9507 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 9508 | c_parser_consume_token (parser); |
| 9509 | else |
| 9510 | break; |
| 9511 | } |
| 9512 | c_parser_require (parser, CPP_GREATER, "expected %<>%>" ); |
| 9513 | return list; |
| 9514 | } |
| 9515 | |
| 9516 | /* Parse an objc-try-catch-finally-statement. |
| 9517 | |
| 9518 | objc-try-catch-finally-statement: |
| 9519 | @try compound-statement objc-catch-list[opt] |
| 9520 | @try compound-statement objc-catch-list[opt] @finally compound-statement |
| 9521 | |
| 9522 | objc-catch-list: |
| 9523 | @catch ( objc-catch-parameter-declaration ) compound-statement |
| 9524 | objc-catch-list @catch ( objc-catch-parameter-declaration ) compound-statement |
| 9525 | |
| 9526 | objc-catch-parameter-declaration: |
| 9527 | parameter-declaration |
| 9528 | '...' |
| 9529 | |
| 9530 | where '...' is to be interpreted literally, that is, it means CPP_ELLIPSIS. |
| 9531 | |
| 9532 | PS: This function is identical to cp_parser_objc_try_catch_finally_statement |
| 9533 | for C++. Keep them in sync. */ |
| 9534 | |
| 9535 | static void |
| 9536 | c_parser_objc_try_catch_finally_statement (c_parser *parser) |
| 9537 | { |
| 9538 | location_t location; |
| 9539 | tree stmt; |
| 9540 | |
| 9541 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_TRY)); |
| 9542 | c_parser_consume_token (parser); |
| 9543 | location = c_parser_peek_token (parser)->location; |
| 9544 | objc_maybe_warn_exceptions (location); |
| 9545 | stmt = c_parser_compound_statement (parser); |
| 9546 | objc_begin_try_stmt (location, stmt); |
| 9547 | |
| 9548 | while (c_parser_next_token_is_keyword (parser, RID_AT_CATCH)) |
| 9549 | { |
| 9550 | struct c_parm *parm; |
| 9551 | tree parameter_declaration = error_mark_node; |
| 9552 | bool seen_open_paren = false; |
| 9553 | |
| 9554 | c_parser_consume_token (parser); |
| 9555 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 9556 | seen_open_paren = true; |
| 9557 | if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) |
| 9558 | { |
| 9559 | /* We have "@catch (...)" (where the '...' are literally |
| 9560 | what is in the code). Skip the '...'. |
| 9561 | parameter_declaration is set to NULL_TREE, and |
| 9562 | objc_being_catch_clauses() knows that that means |
| 9563 | '...'. */ |
| 9564 | c_parser_consume_token (parser); |
| 9565 | parameter_declaration = NULL_TREE; |
| 9566 | } |
| 9567 | else |
| 9568 | { |
| 9569 | /* We have "@catch (NSException *exception)" or something |
| 9570 | like that. Parse the parameter declaration. */ |
| 9571 | parm = c_parser_parameter_declaration (parser, NULL_TREE); |
| 9572 | if (parm == NULL) |
| 9573 | parameter_declaration = error_mark_node; |
| 9574 | else |
| 9575 | parameter_declaration = grokparm (parm, NULL); |
| 9576 | } |
| 9577 | if (seen_open_paren) |
| 9578 | c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 9579 | else |
| 9580 | { |
| 9581 | /* If there was no open parenthesis, we are recovering from |
| 9582 | an error, and we are trying to figure out what mistake |
| 9583 | the user has made. */ |
| 9584 | |
| 9585 | /* If there is an immediate closing parenthesis, the user |
| 9586 | probably forgot the opening one (ie, they typed "@catch |
| 9587 | NSException *e)". Parse the closing parenthesis and keep |
| 9588 | going. */ |
| 9589 | if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) |
| 9590 | c_parser_consume_token (parser); |
| 9591 | |
| 9592 | /* If these is no immediate closing parenthesis, the user |
| 9593 | probably doesn't know that parenthesis are required at |
| 9594 | all (ie, they typed "@catch NSException *e"). So, just |
| 9595 | forget about the closing parenthesis and keep going. */ |
| 9596 | } |
| 9597 | objc_begin_catch_clause (parameter_declaration); |
| 9598 | if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>" )) |
| 9599 | c_parser_compound_statement_nostart (parser); |
| 9600 | objc_finish_catch_clause (); |
| 9601 | } |
| 9602 | if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY)) |
| 9603 | { |
| 9604 | c_parser_consume_token (parser); |
| 9605 | location = c_parser_peek_token (parser)->location; |
| 9606 | stmt = c_parser_compound_statement (parser); |
| 9607 | objc_build_finally_clause (location, stmt); |
| 9608 | } |
| 9609 | objc_finish_try_stmt (); |
| 9610 | } |
| 9611 | |
| 9612 | /* Parse an objc-synchronized-statement. |
| 9613 | |
| 9614 | objc-synchronized-statement: |
| 9615 | @synchronized ( expression ) compound-statement |
| 9616 | */ |
| 9617 | |
| 9618 | static void |
| 9619 | c_parser_objc_synchronized_statement (c_parser *parser) |
| 9620 | { |
| 9621 | location_t loc; |
| 9622 | tree expr, stmt; |
| 9623 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED)); |
| 9624 | c_parser_consume_token (parser); |
| 9625 | loc = c_parser_peek_token (parser)->location; |
| 9626 | objc_maybe_warn_exceptions (loc); |
| 9627 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 9628 | { |
| 9629 | struct c_expr ce = c_parser_expression (parser); |
| 9630 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); |
| 9631 | expr = ce.value; |
| 9632 | expr = c_fully_fold (expr, false, NULL); |
| 9633 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 9634 | } |
| 9635 | else |
| 9636 | expr = error_mark_node; |
| 9637 | stmt = c_parser_compound_statement (parser); |
| 9638 | objc_build_synchronized (loc, expr, stmt); |
| 9639 | } |
| 9640 | |
| 9641 | /* Parse an objc-selector; return NULL_TREE without an error if the |
| 9642 | next token is not an objc-selector. |
| 9643 | |
| 9644 | objc-selector: |
| 9645 | identifier |
| 9646 | one of |
| 9647 | enum struct union if else while do for switch case default |
| 9648 | break continue return goto asm sizeof typeof __alignof |
| 9649 | unsigned long const short volatile signed restrict _Complex |
| 9650 | in out inout bycopy byref oneway int char float double void _Bool |
| 9651 | _Atomic |
| 9652 | |
| 9653 | ??? Why this selection of keywords but not, for example, storage |
| 9654 | class specifiers? */ |
| 9655 | |
| 9656 | static tree |
| 9657 | c_parser_objc_selector (c_parser *parser) |
| 9658 | { |
| 9659 | c_token *token = c_parser_peek_token (parser); |
| 9660 | tree value = token->value; |
| 9661 | if (token->type == CPP_NAME) |
| 9662 | { |
| 9663 | c_parser_consume_token (parser); |
| 9664 | return value; |
| 9665 | } |
| 9666 | if (token->type != CPP_KEYWORD) |
| 9667 | return NULL_TREE; |
| 9668 | switch (token->keyword) |
| 9669 | { |
| 9670 | case RID_ENUM: |
| 9671 | case RID_STRUCT: |
| 9672 | case RID_UNION: |
| 9673 | case RID_IF: |
| 9674 | case RID_ELSE: |
| 9675 | case RID_WHILE: |
| 9676 | case RID_DO: |
| 9677 | case RID_FOR: |
| 9678 | case RID_SWITCH: |
| 9679 | case RID_CASE: |
| 9680 | case RID_DEFAULT: |
| 9681 | case RID_BREAK: |
| 9682 | case RID_CONTINUE: |
| 9683 | case RID_RETURN: |
| 9684 | case RID_GOTO: |
| 9685 | case RID_ASM: |
| 9686 | case RID_SIZEOF: |
| 9687 | case RID_TYPEOF: |
| 9688 | case RID_ALIGNOF: |
| 9689 | case RID_UNSIGNED: |
| 9690 | case RID_LONG: |
| 9691 | case RID_CONST: |
| 9692 | case RID_SHORT: |
| 9693 | case RID_VOLATILE: |
| 9694 | case RID_SIGNED: |
| 9695 | case RID_RESTRICT: |
| 9696 | case RID_COMPLEX: |
| 9697 | case RID_IN: |
| 9698 | case RID_OUT: |
| 9699 | case RID_INOUT: |
| 9700 | case RID_BYCOPY: |
| 9701 | case RID_BYREF: |
| 9702 | case RID_ONEWAY: |
| 9703 | case RID_INT: |
| 9704 | case RID_CHAR: |
| 9705 | case RID_FLOAT: |
| 9706 | case RID_DOUBLE: |
| 9707 | CASE_RID_FLOATN_NX: |
| 9708 | case RID_VOID: |
| 9709 | case RID_BOOL: |
| 9710 | case RID_ATOMIC: |
| 9711 | case RID_AUTO_TYPE: |
| 9712 | case RID_INT_N_0: |
| 9713 | case RID_INT_N_1: |
| 9714 | case RID_INT_N_2: |
| 9715 | case RID_INT_N_3: |
| 9716 | c_parser_consume_token (parser); |
| 9717 | return value; |
| 9718 | default: |
| 9719 | return NULL_TREE; |
| 9720 | } |
| 9721 | } |
| 9722 | |
| 9723 | /* Parse an objc-selector-arg. |
| 9724 | |
| 9725 | objc-selector-arg: |
| 9726 | objc-selector |
| 9727 | objc-keywordname-list |
| 9728 | |
| 9729 | objc-keywordname-list: |
| 9730 | objc-keywordname |
| 9731 | objc-keywordname-list objc-keywordname |
| 9732 | |
| 9733 | objc-keywordname: |
| 9734 | objc-selector : |
| 9735 | : |
| 9736 | */ |
| 9737 | |
| 9738 | static tree |
| 9739 | c_parser_objc_selector_arg (c_parser *parser) |
| 9740 | { |
| 9741 | tree sel = c_parser_objc_selector (parser); |
| 9742 | tree list = NULL_TREE; |
| 9743 | if (sel && c_parser_next_token_is_not (parser, CPP_COLON)) |
| 9744 | return sel; |
| 9745 | while (true) |
| 9746 | { |
| 9747 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>" )) |
| 9748 | return list; |
| 9749 | list = chainon (list, build_tree_list (sel, NULL_TREE)); |
| 9750 | sel = c_parser_objc_selector (parser); |
| 9751 | if (!sel && c_parser_next_token_is_not (parser, CPP_COLON)) |
| 9752 | break; |
| 9753 | } |
| 9754 | return list; |
| 9755 | } |
| 9756 | |
| 9757 | /* Parse an objc-receiver. |
| 9758 | |
| 9759 | objc-receiver: |
| 9760 | expression |
| 9761 | class-name |
| 9762 | type-name |
| 9763 | */ |
| 9764 | |
| 9765 | static tree |
| 9766 | c_parser_objc_receiver (c_parser *parser) |
| 9767 | { |
| 9768 | location_t loc = c_parser_peek_token (parser)->location; |
| 9769 | |
| 9770 | if (c_parser_peek_token (parser)->type == CPP_NAME |
| 9771 | && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME |
| 9772 | || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)) |
| 9773 | { |
| 9774 | tree id = c_parser_peek_token (parser)->value; |
| 9775 | c_parser_consume_token (parser); |
| 9776 | return objc_get_class_reference (id); |
| 9777 | } |
| 9778 | struct c_expr ce = c_parser_expression (parser); |
| 9779 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); |
| 9780 | return c_fully_fold (ce.value, false, NULL); |
| 9781 | } |
| 9782 | |
| 9783 | /* Parse objc-message-args. |
| 9784 | |
| 9785 | objc-message-args: |
| 9786 | objc-selector |
| 9787 | objc-keywordarg-list |
| 9788 | |
| 9789 | objc-keywordarg-list: |
| 9790 | objc-keywordarg |
| 9791 | objc-keywordarg-list objc-keywordarg |
| 9792 | |
| 9793 | objc-keywordarg: |
| 9794 | objc-selector : objc-keywordexpr |
| 9795 | : objc-keywordexpr |
| 9796 | */ |
| 9797 | |
| 9798 | static tree |
| 9799 | c_parser_objc_message_args (c_parser *parser) |
| 9800 | { |
| 9801 | tree sel = c_parser_objc_selector (parser); |
| 9802 | tree list = NULL_TREE; |
| 9803 | if (sel && c_parser_next_token_is_not (parser, CPP_COLON)) |
| 9804 | return sel; |
| 9805 | while (true) |
| 9806 | { |
| 9807 | tree keywordexpr; |
| 9808 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>" )) |
| 9809 | return error_mark_node; |
| 9810 | keywordexpr = c_parser_objc_keywordexpr (parser); |
| 9811 | list = chainon (list, build_tree_list (sel, keywordexpr)); |
| 9812 | sel = c_parser_objc_selector (parser); |
| 9813 | if (!sel && c_parser_next_token_is_not (parser, CPP_COLON)) |
| 9814 | break; |
| 9815 | } |
| 9816 | return list; |
| 9817 | } |
| 9818 | |
| 9819 | /* Parse an objc-keywordexpr. |
| 9820 | |
| 9821 | objc-keywordexpr: |
| 9822 | nonempty-expr-list |
| 9823 | */ |
| 9824 | |
| 9825 | static tree |
| 9826 | c_parser_objc_keywordexpr (c_parser *parser) |
| 9827 | { |
| 9828 | tree ret; |
| 9829 | vec<tree, va_gc> *expr_list = c_parser_expr_list (parser, true, true, |
| 9830 | NULL, NULL, NULL, NULL); |
| 9831 | if (vec_safe_length (expr_list) == 1) |
| 9832 | { |
| 9833 | /* Just return the expression, remove a level of |
| 9834 | indirection. */ |
| 9835 | ret = (*expr_list)[0]; |
| 9836 | } |
| 9837 | else |
| 9838 | { |
| 9839 | /* We have a comma expression, we will collapse later. */ |
| 9840 | ret = build_tree_list_vec (expr_list); |
| 9841 | } |
| 9842 | release_tree_vector (expr_list); |
| 9843 | return ret; |
| 9844 | } |
| 9845 | |
| 9846 | /* A check, needed in several places, that ObjC interface, implementation or |
| 9847 | method definitions are not prefixed by incorrect items. */ |
| 9848 | static bool |
| 9849 | c_parser_objc_diagnose_bad_element_prefix (c_parser *parser, |
| 9850 | struct c_declspecs *specs) |
| 9851 | { |
| 9852 | if (!specs->declspecs_seen_p || specs->non_sc_seen_p |
| 9853 | || specs->typespec_kind != ctsk_none) |
| 9854 | { |
| 9855 | c_parser_error (parser, |
| 9856 | "no type or storage class may be specified here," ); |
| 9857 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 9858 | return true; |
| 9859 | } |
| 9860 | return false; |
| 9861 | } |
| 9862 | |
| 9863 | /* Parse an Objective-C @property declaration. The syntax is: |
| 9864 | |
| 9865 | objc-property-declaration: |
| 9866 | '@property' objc-property-attributes[opt] struct-declaration ; |
| 9867 | |
| 9868 | objc-property-attributes: |
| 9869 | '(' objc-property-attribute-list ')' |
| 9870 | |
| 9871 | objc-property-attribute-list: |
| 9872 | objc-property-attribute |
| 9873 | objc-property-attribute-list, objc-property-attribute |
| 9874 | |
| 9875 | objc-property-attribute |
| 9876 | 'getter' = identifier |
| 9877 | 'setter' = identifier |
| 9878 | 'readonly' |
| 9879 | 'readwrite' |
| 9880 | 'assign' |
| 9881 | 'retain' |
| 9882 | 'copy' |
| 9883 | 'nonatomic' |
| 9884 | |
| 9885 | For example: |
| 9886 | @property NSString *name; |
| 9887 | @property (readonly) id object; |
| 9888 | @property (retain, nonatomic, getter=getTheName) id name; |
| 9889 | @property int a, b, c; |
| 9890 | |
| 9891 | PS: This function is identical to cp_parser_objc_at_propery_declaration |
| 9892 | for C++. Keep them in sync. */ |
| 9893 | static void |
| 9894 | c_parser_objc_at_property_declaration (c_parser *parser) |
| 9895 | { |
| 9896 | /* The following variables hold the attributes of the properties as |
| 9897 | parsed. They are 'false' or 'NULL_TREE' if the attribute was not |
| 9898 | seen. When we see an attribute, we set them to 'true' (if they |
| 9899 | are boolean properties) or to the identifier (if they have an |
| 9900 | argument, ie, for getter and setter). Note that here we only |
| 9901 | parse the list of attributes, check the syntax and accumulate the |
| 9902 | attributes that we find. objc_add_property_declaration() will |
| 9903 | then process the information. */ |
| 9904 | bool property_assign = false; |
| 9905 | bool property_copy = false; |
| 9906 | tree property_getter_ident = NULL_TREE; |
| 9907 | bool property_nonatomic = false; |
| 9908 | bool property_readonly = false; |
| 9909 | bool property_readwrite = false; |
| 9910 | bool property_retain = false; |
| 9911 | tree property_setter_ident = NULL_TREE; |
| 9912 | |
| 9913 | /* 'properties' is the list of properties that we read. Usually a |
| 9914 | single one, but maybe more (eg, in "@property int a, b, c;" there |
| 9915 | are three). */ |
| 9916 | tree properties; |
| 9917 | location_t loc; |
| 9918 | |
| 9919 | loc = c_parser_peek_token (parser)->location; |
| 9920 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROPERTY)); |
| 9921 | |
| 9922 | c_parser_consume_token (parser); /* Eat '@property'. */ |
| 9923 | |
| 9924 | /* Parse the optional attribute list... */ |
| 9925 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 9926 | { |
| 9927 | /* Eat the '(' */ |
| 9928 | c_parser_consume_token (parser); |
| 9929 | |
| 9930 | /* Property attribute keywords are valid now. */ |
| 9931 | parser->objc_property_attr_context = true; |
| 9932 | |
| 9933 | while (true) |
| 9934 | { |
| 9935 | bool syntax_error = false; |
| 9936 | c_token *token = c_parser_peek_token (parser); |
| 9937 | enum rid keyword; |
| 9938 | |
| 9939 | if (token->type != CPP_KEYWORD) |
| 9940 | { |
| 9941 | if (token->type == CPP_CLOSE_PAREN) |
| 9942 | c_parser_error (parser, "expected identifier" ); |
| 9943 | else |
| 9944 | { |
| 9945 | c_parser_consume_token (parser); |
| 9946 | c_parser_error (parser, "unknown property attribute" ); |
| 9947 | } |
| 9948 | break; |
| 9949 | } |
| 9950 | keyword = token->keyword; |
| 9951 | c_parser_consume_token (parser); |
| 9952 | switch (keyword) |
| 9953 | { |
| 9954 | case RID_ASSIGN: property_assign = true; break; |
| 9955 | case RID_COPY: property_copy = true; break; |
| 9956 | case RID_NONATOMIC: property_nonatomic = true; break; |
| 9957 | case RID_READONLY: property_readonly = true; break; |
| 9958 | case RID_READWRITE: property_readwrite = true; break; |
| 9959 | case RID_RETAIN: property_retain = true; break; |
| 9960 | |
| 9961 | case RID_GETTER: |
| 9962 | case RID_SETTER: |
| 9963 | if (c_parser_next_token_is_not (parser, CPP_EQ)) |
| 9964 | { |
| 9965 | if (keyword == RID_GETTER) |
| 9966 | c_parser_error (parser, |
| 9967 | "missing %<=%> (after %<getter%> attribute)" ); |
| 9968 | else |
| 9969 | c_parser_error (parser, |
| 9970 | "missing %<=%> (after %<setter%> attribute)" ); |
| 9971 | syntax_error = true; |
| 9972 | break; |
| 9973 | } |
| 9974 | c_parser_consume_token (parser); /* eat the = */ |
| 9975 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 9976 | { |
| 9977 | c_parser_error (parser, "expected identifier" ); |
| 9978 | syntax_error = true; |
| 9979 | break; |
| 9980 | } |
| 9981 | if (keyword == RID_SETTER) |
| 9982 | { |
| 9983 | if (property_setter_ident != NULL_TREE) |
| 9984 | c_parser_error (parser, "the %<setter%> attribute may only be specified once" ); |
| 9985 | else |
| 9986 | property_setter_ident = c_parser_peek_token (parser)->value; |
| 9987 | c_parser_consume_token (parser); |
| 9988 | if (c_parser_next_token_is_not (parser, CPP_COLON)) |
| 9989 | c_parser_error (parser, "setter name must terminate with %<:%>" ); |
| 9990 | else |
| 9991 | c_parser_consume_token (parser); |
| 9992 | } |
| 9993 | else |
| 9994 | { |
| 9995 | if (property_getter_ident != NULL_TREE) |
| 9996 | c_parser_error (parser, "the %<getter%> attribute may only be specified once" ); |
| 9997 | else |
| 9998 | property_getter_ident = c_parser_peek_token (parser)->value; |
| 9999 | c_parser_consume_token (parser); |
| 10000 | } |
| 10001 | break; |
| 10002 | default: |
| 10003 | c_parser_error (parser, "unknown property attribute" ); |
| 10004 | syntax_error = true; |
| 10005 | break; |
| 10006 | } |
| 10007 | |
| 10008 | if (syntax_error) |
| 10009 | break; |
| 10010 | |
| 10011 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 10012 | c_parser_consume_token (parser); |
| 10013 | else |
| 10014 | break; |
| 10015 | } |
| 10016 | parser->objc_property_attr_context = false; |
| 10017 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 10018 | } |
| 10019 | /* ... and the property declaration(s). */ |
| 10020 | properties = c_parser_struct_declaration (parser); |
| 10021 | |
| 10022 | if (properties == error_mark_node) |
| 10023 | { |
| 10024 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
| 10025 | parser->error = false; |
| 10026 | return; |
| 10027 | } |
| 10028 | |
| 10029 | if (properties == NULL_TREE) |
| 10030 | c_parser_error (parser, "expected identifier" ); |
| 10031 | else |
| 10032 | { |
| 10033 | /* Comma-separated properties are chained together in |
| 10034 | reverse order; add them one by one. */ |
| 10035 | properties = nreverse (properties); |
| 10036 | |
| 10037 | for (; properties; properties = TREE_CHAIN (properties)) |
| 10038 | objc_add_property_declaration (loc, copy_node (properties), |
| 10039 | property_readonly, property_readwrite, |
| 10040 | property_assign, property_retain, |
| 10041 | property_copy, property_nonatomic, |
| 10042 | property_getter_ident, property_setter_ident); |
| 10043 | } |
| 10044 | |
| 10045 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>" ); |
| 10046 | parser->error = false; |
| 10047 | } |
| 10048 | |
| 10049 | /* Parse an Objective-C @synthesize declaration. The syntax is: |
| 10050 | |
| 10051 | objc-synthesize-declaration: |
| 10052 | @synthesize objc-synthesize-identifier-list ; |
| 10053 | |
| 10054 | objc-synthesize-identifier-list: |
| 10055 | objc-synthesize-identifier |
| 10056 | objc-synthesize-identifier-list, objc-synthesize-identifier |
| 10057 | |
| 10058 | objc-synthesize-identifier |
| 10059 | identifier |
| 10060 | identifier = identifier |
| 10061 | |
| 10062 | For example: |
| 10063 | @synthesize MyProperty; |
| 10064 | @synthesize OneProperty, AnotherProperty=MyIvar, YetAnotherProperty; |
| 10065 | |
| 10066 | PS: This function is identical to cp_parser_objc_at_synthesize_declaration |
| 10067 | for C++. Keep them in sync. |
| 10068 | */ |
| 10069 | static void |
| 10070 | c_parser_objc_at_synthesize_declaration (c_parser *parser) |
| 10071 | { |
| 10072 | tree list = NULL_TREE; |
| 10073 | location_t loc; |
| 10074 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNTHESIZE)); |
| 10075 | loc = c_parser_peek_token (parser)->location; |
| 10076 | |
| 10077 | c_parser_consume_token (parser); |
| 10078 | while (true) |
| 10079 | { |
| 10080 | tree property, ivar; |
| 10081 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 10082 | { |
| 10083 | c_parser_error (parser, "expected identifier" ); |
| 10084 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
| 10085 | /* Once we find the semicolon, we can resume normal parsing. |
| 10086 | We have to reset parser->error manually because |
| 10087 | c_parser_skip_until_found() won't reset it for us if the |
| 10088 | next token is precisely a semicolon. */ |
| 10089 | parser->error = false; |
| 10090 | return; |
| 10091 | } |
| 10092 | property = c_parser_peek_token (parser)->value; |
| 10093 | c_parser_consume_token (parser); |
| 10094 | if (c_parser_next_token_is (parser, CPP_EQ)) |
| 10095 | { |
| 10096 | c_parser_consume_token (parser); |
| 10097 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 10098 | { |
| 10099 | c_parser_error (parser, "expected identifier" ); |
| 10100 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
| 10101 | parser->error = false; |
| 10102 | return; |
| 10103 | } |
| 10104 | ivar = c_parser_peek_token (parser)->value; |
| 10105 | c_parser_consume_token (parser); |
| 10106 | } |
| 10107 | else |
| 10108 | ivar = NULL_TREE; |
| 10109 | list = chainon (list, build_tree_list (ivar, property)); |
| 10110 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 10111 | c_parser_consume_token (parser); |
| 10112 | else |
| 10113 | break; |
| 10114 | } |
| 10115 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>" ); |
| 10116 | objc_add_synthesize_declaration (loc, list); |
| 10117 | } |
| 10118 | |
| 10119 | /* Parse an Objective-C @dynamic declaration. The syntax is: |
| 10120 | |
| 10121 | objc-dynamic-declaration: |
| 10122 | @dynamic identifier-list ; |
| 10123 | |
| 10124 | For example: |
| 10125 | @dynamic MyProperty; |
| 10126 | @dynamic MyProperty, AnotherProperty; |
| 10127 | |
| 10128 | PS: This function is identical to cp_parser_objc_at_dynamic_declaration |
| 10129 | for C++. Keep them in sync. |
| 10130 | */ |
| 10131 | static void |
| 10132 | c_parser_objc_at_dynamic_declaration (c_parser *parser) |
| 10133 | { |
| 10134 | tree list = NULL_TREE; |
| 10135 | location_t loc; |
| 10136 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_DYNAMIC)); |
| 10137 | loc = c_parser_peek_token (parser)->location; |
| 10138 | |
| 10139 | c_parser_consume_token (parser); |
| 10140 | while (true) |
| 10141 | { |
| 10142 | tree property; |
| 10143 | if (c_parser_next_token_is_not (parser, CPP_NAME)) |
| 10144 | { |
| 10145 | c_parser_error (parser, "expected identifier" ); |
| 10146 | c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); |
| 10147 | parser->error = false; |
| 10148 | return; |
| 10149 | } |
| 10150 | property = c_parser_peek_token (parser)->value; |
| 10151 | list = chainon (list, build_tree_list (NULL_TREE, property)); |
| 10152 | c_parser_consume_token (parser); |
| 10153 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 10154 | c_parser_consume_token (parser); |
| 10155 | else |
| 10156 | break; |
| 10157 | } |
| 10158 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>" ); |
| 10159 | objc_add_dynamic_declaration (loc, list); |
| 10160 | } |
| 10161 | |
| 10162 | |
| 10163 | /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore |
| 10164 | should be considered, statements. ALLOW_STMT is true if we're within |
| 10165 | the context of a function and such pragmas are to be allowed. Returns |
| 10166 | true if we actually parsed such a pragma. */ |
| 10167 | |
| 10168 | static bool |
| 10169 | c_parser_pragma (c_parser *parser, enum pragma_context context, bool *if_p) |
| 10170 | { |
| 10171 | unsigned int id; |
| 10172 | const char *construct = NULL; |
| 10173 | |
| 10174 | id = c_parser_peek_token (parser)->pragma_kind; |
| 10175 | gcc_assert (id != PRAGMA_NONE); |
| 10176 | |
| 10177 | switch (id) |
| 10178 | { |
| 10179 | case PRAGMA_OACC_DECLARE: |
| 10180 | c_parser_oacc_declare (parser); |
| 10181 | return false; |
| 10182 | |
| 10183 | case PRAGMA_OACC_ENTER_DATA: |
| 10184 | if (context != pragma_compound) |
| 10185 | { |
| 10186 | construct = "acc enter data" ; |
| 10187 | in_compound: |
| 10188 | if (context == pragma_stmt) |
| 10189 | { |
| 10190 | error_at (c_parser_peek_token (parser)->location, |
| 10191 | "%<#pragma %s%> may only be used in compound " |
| 10192 | "statements" , construct); |
| 10193 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
| 10194 | return false; |
| 10195 | } |
| 10196 | goto bad_stmt; |
| 10197 | } |
| 10198 | c_parser_oacc_enter_exit_data (parser, true); |
| 10199 | return false; |
| 10200 | |
| 10201 | case PRAGMA_OACC_EXIT_DATA: |
| 10202 | if (context != pragma_compound) |
| 10203 | { |
| 10204 | construct = "acc exit data" ; |
| 10205 | goto in_compound; |
| 10206 | } |
| 10207 | c_parser_oacc_enter_exit_data (parser, false); |
| 10208 | return false; |
| 10209 | |
| 10210 | case PRAGMA_OACC_ROUTINE: |
| 10211 | if (context != pragma_external) |
| 10212 | { |
| 10213 | error_at (c_parser_peek_token (parser)->location, |
| 10214 | "%<#pragma acc routine%> must be at file scope" ); |
| 10215 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
| 10216 | return false; |
| 10217 | } |
| 10218 | c_parser_oacc_routine (parser, context); |
| 10219 | return false; |
| 10220 | |
| 10221 | case PRAGMA_OACC_UPDATE: |
| 10222 | if (context != pragma_compound) |
| 10223 | { |
| 10224 | construct = "acc update" ; |
| 10225 | goto in_compound; |
| 10226 | } |
| 10227 | c_parser_oacc_update (parser); |
| 10228 | return false; |
| 10229 | |
| 10230 | case PRAGMA_OMP_BARRIER: |
| 10231 | if (context != pragma_compound) |
| 10232 | { |
| 10233 | construct = "omp barrier" ; |
| 10234 | goto in_compound; |
| 10235 | } |
| 10236 | c_parser_omp_barrier (parser); |
| 10237 | return false; |
| 10238 | |
| 10239 | case PRAGMA_OMP_FLUSH: |
| 10240 | if (context != pragma_compound) |
| 10241 | { |
| 10242 | construct = "omp flush" ; |
| 10243 | goto in_compound; |
| 10244 | } |
| 10245 | c_parser_omp_flush (parser); |
| 10246 | return false; |
| 10247 | |
| 10248 | case PRAGMA_OMP_TASKWAIT: |
| 10249 | if (context != pragma_compound) |
| 10250 | { |
| 10251 | construct = "omp taskwait" ; |
| 10252 | goto in_compound; |
| 10253 | } |
| 10254 | c_parser_omp_taskwait (parser); |
| 10255 | return false; |
| 10256 | |
| 10257 | case PRAGMA_OMP_TASKYIELD: |
| 10258 | if (context != pragma_compound) |
| 10259 | { |
| 10260 | construct = "omp taskyield" ; |
| 10261 | goto in_compound; |
| 10262 | } |
| 10263 | c_parser_omp_taskyield (parser); |
| 10264 | return false; |
| 10265 | |
| 10266 | case PRAGMA_OMP_CANCEL: |
| 10267 | if (context != pragma_compound) |
| 10268 | { |
| 10269 | construct = "omp cancel" ; |
| 10270 | goto in_compound; |
| 10271 | } |
| 10272 | c_parser_omp_cancel (parser); |
| 10273 | return false; |
| 10274 | |
| 10275 | case PRAGMA_OMP_CANCELLATION_POINT: |
| 10276 | c_parser_omp_cancellation_point (parser, context); |
| 10277 | return false; |
| 10278 | |
| 10279 | case PRAGMA_OMP_THREADPRIVATE: |
| 10280 | c_parser_omp_threadprivate (parser); |
| 10281 | return false; |
| 10282 | |
| 10283 | case PRAGMA_OMP_TARGET: |
| 10284 | return c_parser_omp_target (parser, context, if_p); |
| 10285 | |
| 10286 | case PRAGMA_OMP_END_DECLARE_TARGET: |
| 10287 | c_parser_omp_end_declare_target (parser); |
| 10288 | return false; |
| 10289 | |
| 10290 | case PRAGMA_OMP_SECTION: |
| 10291 | error_at (c_parser_peek_token (parser)->location, |
| 10292 | "%<#pragma omp section%> may only be used in " |
| 10293 | "%<#pragma omp sections%> construct" ); |
| 10294 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
| 10295 | return false; |
| 10296 | |
| 10297 | case PRAGMA_OMP_DECLARE: |
| 10298 | c_parser_omp_declare (parser, context); |
| 10299 | return false; |
| 10300 | |
| 10301 | case PRAGMA_OMP_ORDERED: |
| 10302 | return c_parser_omp_ordered (parser, context, if_p); |
| 10303 | |
| 10304 | case PRAGMA_IVDEP: |
| 10305 | c_parser_consume_pragma (parser); |
| 10306 | c_parser_skip_to_pragma_eol (parser); |
| 10307 | if (!c_parser_next_token_is_keyword (parser, RID_FOR) |
| 10308 | && !c_parser_next_token_is_keyword (parser, RID_WHILE) |
| 10309 | && !c_parser_next_token_is_keyword (parser, RID_DO)) |
| 10310 | { |
| 10311 | c_parser_error (parser, "for, while or do statement expected" ); |
| 10312 | return false; |
| 10313 | } |
| 10314 | if (c_parser_next_token_is_keyword (parser, RID_FOR)) |
| 10315 | c_parser_for_statement (parser, true, if_p); |
| 10316 | else if (c_parser_next_token_is_keyword (parser, RID_WHILE)) |
| 10317 | c_parser_while_statement (parser, true, if_p); |
| 10318 | else |
| 10319 | c_parser_do_statement (parser, true); |
| 10320 | return false; |
| 10321 | |
| 10322 | case PRAGMA_GCC_PCH_PREPROCESS: |
| 10323 | c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first" ); |
| 10324 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
| 10325 | return false; |
| 10326 | |
| 10327 | case PRAGMA_CILK_SIMD: |
| 10328 | if (!c_parser_cilk_verify_simd (parser, context)) |
| 10329 | return false; |
| 10330 | c_parser_consume_pragma (parser); |
| 10331 | c_parser_cilk_simd (parser, if_p); |
| 10332 | return false; |
| 10333 | case PRAGMA_CILK_GRAINSIZE: |
| 10334 | if (!flag_cilkplus) |
| 10335 | { |
| 10336 | warning (0, "%<#pragma grainsize%> ignored because -fcilkplus is not" |
| 10337 | " enabled" ); |
| 10338 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
| 10339 | return false; |
| 10340 | } |
| 10341 | if (context == pragma_external) |
| 10342 | { |
| 10343 | error_at (c_parser_peek_token (parser)->location, |
| 10344 | "%<#pragma grainsize%> must be inside a function" ); |
| 10345 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
| 10346 | return false; |
| 10347 | } |
| 10348 | c_parser_cilk_grainsize (parser, if_p); |
| 10349 | return false; |
| 10350 | |
| 10351 | case PRAGMA_OACC_WAIT: |
| 10352 | if (context != pragma_compound) |
| 10353 | { |
| 10354 | construct = "acc wait" ; |
| 10355 | goto in_compound; |
| 10356 | } |
| 10357 | /* FALL THROUGH. */ |
| 10358 | |
| 10359 | default: |
| 10360 | if (id < PRAGMA_FIRST_EXTERNAL) |
| 10361 | { |
| 10362 | if (context != pragma_stmt && context != pragma_compound) |
| 10363 | { |
| 10364 | bad_stmt: |
| 10365 | c_parser_error (parser, "expected declaration specifiers" ); |
| 10366 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
| 10367 | return false; |
| 10368 | } |
| 10369 | c_parser_omp_construct (parser, if_p); |
| 10370 | return true; |
| 10371 | } |
| 10372 | break; |
| 10373 | } |
| 10374 | |
| 10375 | c_parser_consume_pragma (parser); |
| 10376 | c_invoke_pragma_handler (id); |
| 10377 | |
| 10378 | /* Skip to EOL, but suppress any error message. Those will have been |
| 10379 | generated by the handler routine through calling error, as opposed |
| 10380 | to calling c_parser_error. */ |
| 10381 | parser->error = true; |
| 10382 | c_parser_skip_to_pragma_eol (parser); |
| 10383 | |
| 10384 | return false; |
| 10385 | } |
| 10386 | |
| 10387 | /* The interface the pragma parsers have to the lexer. */ |
| 10388 | |
| 10389 | enum cpp_ttype |
| 10390 | pragma_lex (tree *value, location_t *loc) |
| 10391 | { |
| 10392 | c_token *tok = c_parser_peek_token (the_parser); |
| 10393 | enum cpp_ttype ret = tok->type; |
| 10394 | |
| 10395 | *value = tok->value; |
| 10396 | if (loc) |
| 10397 | *loc = tok->location; |
| 10398 | |
| 10399 | if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF) |
| 10400 | ret = CPP_EOF; |
| 10401 | else |
| 10402 | { |
| 10403 | if (ret == CPP_KEYWORD) |
| 10404 | ret = CPP_NAME; |
| 10405 | c_parser_consume_token (the_parser); |
| 10406 | } |
| 10407 | |
| 10408 | return ret; |
| 10409 | } |
| 10410 | |
| 10411 | static void |
| 10412 | c_parser_pragma_pch_preprocess (c_parser *parser) |
| 10413 | { |
| 10414 | tree name = NULL; |
| 10415 | |
| 10416 | c_parser_consume_pragma (parser); |
| 10417 | if (c_parser_next_token_is (parser, CPP_STRING)) |
| 10418 | { |
| 10419 | name = c_parser_peek_token (parser)->value; |
| 10420 | c_parser_consume_token (parser); |
| 10421 | } |
| 10422 | else |
| 10423 | c_parser_error (parser, "expected string literal" ); |
| 10424 | c_parser_skip_to_pragma_eol (parser); |
| 10425 | |
| 10426 | if (name) |
| 10427 | c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name)); |
| 10428 | } |
| 10429 | |
| 10430 | /* OpenACC and OpenMP parsing routines. */ |
| 10431 | |
| 10432 | /* Returns name of the next clause. |
| 10433 | If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and |
| 10434 | the token is not consumed. Otherwise appropriate pragma_omp_clause is |
| 10435 | returned and the token is consumed. */ |
| 10436 | |
| 10437 | static pragma_omp_clause |
| 10438 | c_parser_omp_clause_name (c_parser *parser) |
| 10439 | { |
| 10440 | pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE; |
| 10441 | |
| 10442 | if (c_parser_next_token_is_keyword (parser, RID_AUTO)) |
| 10443 | result = PRAGMA_OACC_CLAUSE_AUTO; |
| 10444 | else if (c_parser_next_token_is_keyword (parser, RID_IF)) |
| 10445 | result = PRAGMA_OMP_CLAUSE_IF; |
| 10446 | else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)) |
| 10447 | result = PRAGMA_OMP_CLAUSE_DEFAULT; |
| 10448 | else if (c_parser_next_token_is_keyword (parser, RID_FOR)) |
| 10449 | result = PRAGMA_OMP_CLAUSE_FOR; |
| 10450 | else if (c_parser_next_token_is (parser, CPP_NAME)) |
| 10451 | { |
| 10452 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 10453 | |
| 10454 | switch (p[0]) |
| 10455 | { |
| 10456 | case 'a': |
| 10457 | if (!strcmp ("aligned" , p)) |
| 10458 | result = PRAGMA_OMP_CLAUSE_ALIGNED; |
| 10459 | else if (!strcmp ("async" , p)) |
| 10460 | result = PRAGMA_OACC_CLAUSE_ASYNC; |
| 10461 | break; |
| 10462 | case 'c': |
| 10463 | if (!strcmp ("collapse" , p)) |
| 10464 | result = PRAGMA_OMP_CLAUSE_COLLAPSE; |
| 10465 | else if (!strcmp ("copy" , p)) |
| 10466 | result = PRAGMA_OACC_CLAUSE_COPY; |
| 10467 | else if (!strcmp ("copyin" , p)) |
| 10468 | result = PRAGMA_OMP_CLAUSE_COPYIN; |
| 10469 | else if (!strcmp ("copyout" , p)) |
| 10470 | result = PRAGMA_OACC_CLAUSE_COPYOUT; |
| 10471 | else if (!strcmp ("copyprivate" , p)) |
| 10472 | result = PRAGMA_OMP_CLAUSE_COPYPRIVATE; |
| 10473 | else if (!strcmp ("create" , p)) |
| 10474 | result = PRAGMA_OACC_CLAUSE_CREATE; |
| 10475 | break; |
| 10476 | case 'd': |
| 10477 | if (!strcmp ("defaultmap" , p)) |
| 10478 | result = PRAGMA_OMP_CLAUSE_DEFAULTMAP; |
| 10479 | else if (!strcmp ("delete" , p)) |
| 10480 | result = PRAGMA_OACC_CLAUSE_DELETE; |
| 10481 | else if (!strcmp ("depend" , p)) |
| 10482 | result = PRAGMA_OMP_CLAUSE_DEPEND; |
| 10483 | else if (!strcmp ("device" , p)) |
| 10484 | result = PRAGMA_OMP_CLAUSE_DEVICE; |
| 10485 | else if (!strcmp ("deviceptr" , p)) |
| 10486 | result = PRAGMA_OACC_CLAUSE_DEVICEPTR; |
| 10487 | else if (!strcmp ("device_resident" , p)) |
| 10488 | result = PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT; |
| 10489 | else if (!strcmp ("dist_schedule" , p)) |
| 10490 | result = PRAGMA_OMP_CLAUSE_DIST_SCHEDULE; |
| 10491 | break; |
| 10492 | case 'f': |
| 10493 | if (!strcmp ("final" , p)) |
| 10494 | result = PRAGMA_OMP_CLAUSE_FINAL; |
| 10495 | else if (!strcmp ("firstprivate" , p)) |
| 10496 | result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE; |
| 10497 | else if (!strcmp ("from" , p)) |
| 10498 | result = PRAGMA_OMP_CLAUSE_FROM; |
| 10499 | break; |
| 10500 | case 'g': |
| 10501 | if (!strcmp ("gang" , p)) |
| 10502 | result = PRAGMA_OACC_CLAUSE_GANG; |
| 10503 | else if (!strcmp ("grainsize" , p)) |
| 10504 | result = PRAGMA_OMP_CLAUSE_GRAINSIZE; |
| 10505 | break; |
| 10506 | case 'h': |
| 10507 | if (!strcmp ("hint" , p)) |
| 10508 | result = PRAGMA_OMP_CLAUSE_HINT; |
| 10509 | else if (!strcmp ("host" , p)) |
| 10510 | result = PRAGMA_OACC_CLAUSE_HOST; |
| 10511 | break; |
| 10512 | case 'i': |
| 10513 | if (!strcmp ("inbranch" , p)) |
| 10514 | result = PRAGMA_OMP_CLAUSE_INBRANCH; |
| 10515 | else if (!strcmp ("independent" , p)) |
| 10516 | result = PRAGMA_OACC_CLAUSE_INDEPENDENT; |
| 10517 | else if (!strcmp ("is_device_ptr" , p)) |
| 10518 | result = PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR; |
| 10519 | break; |
| 10520 | case 'l': |
| 10521 | if (!strcmp ("lastprivate" , p)) |
| 10522 | result = PRAGMA_OMP_CLAUSE_LASTPRIVATE; |
| 10523 | else if (!strcmp ("linear" , p)) |
| 10524 | result = PRAGMA_OMP_CLAUSE_LINEAR; |
| 10525 | else if (!strcmp ("link" , p)) |
| 10526 | result = PRAGMA_OMP_CLAUSE_LINK; |
| 10527 | break; |
| 10528 | case 'm': |
| 10529 | if (!strcmp ("map" , p)) |
| 10530 | result = PRAGMA_OMP_CLAUSE_MAP; |
| 10531 | else if (!strcmp ("mergeable" , p)) |
| 10532 | result = PRAGMA_OMP_CLAUSE_MERGEABLE; |
| 10533 | else if (flag_cilkplus && !strcmp ("mask" , p)) |
| 10534 | result = PRAGMA_CILK_CLAUSE_MASK; |
| 10535 | break; |
| 10536 | case 'n': |
| 10537 | if (!strcmp ("nogroup" , p)) |
| 10538 | result = PRAGMA_OMP_CLAUSE_NOGROUP; |
| 10539 | else if (!strcmp ("notinbranch" , p)) |
| 10540 | result = PRAGMA_OMP_CLAUSE_NOTINBRANCH; |
| 10541 | else if (!strcmp ("nowait" , p)) |
| 10542 | result = PRAGMA_OMP_CLAUSE_NOWAIT; |
| 10543 | else if (!strcmp ("num_gangs" , p)) |
| 10544 | result = PRAGMA_OACC_CLAUSE_NUM_GANGS; |
| 10545 | else if (!strcmp ("num_tasks" , p)) |
| 10546 | result = PRAGMA_OMP_CLAUSE_NUM_TASKS; |
| 10547 | else if (!strcmp ("num_teams" , p)) |
| 10548 | result = PRAGMA_OMP_CLAUSE_NUM_TEAMS; |
| 10549 | else if (!strcmp ("num_threads" , p)) |
| 10550 | result = PRAGMA_OMP_CLAUSE_NUM_THREADS; |
| 10551 | else if (!strcmp ("num_workers" , p)) |
| 10552 | result = PRAGMA_OACC_CLAUSE_NUM_WORKERS; |
| 10553 | else if (flag_cilkplus && !strcmp ("nomask" , p)) |
| 10554 | result = PRAGMA_CILK_CLAUSE_NOMASK; |
| 10555 | break; |
| 10556 | case 'o': |
| 10557 | if (!strcmp ("ordered" , p)) |
| 10558 | result = PRAGMA_OMP_CLAUSE_ORDERED; |
| 10559 | break; |
| 10560 | case 'p': |
| 10561 | if (!strcmp ("parallel" , p)) |
| 10562 | result = PRAGMA_OMP_CLAUSE_PARALLEL; |
| 10563 | else if (!strcmp ("present" , p)) |
| 10564 | result = PRAGMA_OACC_CLAUSE_PRESENT; |
| 10565 | else if (!strcmp ("present_or_copy" , p) |
| 10566 | || !strcmp ("pcopy" , p)) |
| 10567 | result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY; |
| 10568 | else if (!strcmp ("present_or_copyin" , p) |
| 10569 | || !strcmp ("pcopyin" , p)) |
| 10570 | result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN; |
| 10571 | else if (!strcmp ("present_or_copyout" , p) |
| 10572 | || !strcmp ("pcopyout" , p)) |
| 10573 | result = PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT; |
| 10574 | else if (!strcmp ("present_or_create" , p) |
| 10575 | || !strcmp ("pcreate" , p)) |
| 10576 | result = PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE; |
| 10577 | else if (!strcmp ("priority" , p)) |
| 10578 | result = PRAGMA_OMP_CLAUSE_PRIORITY; |
| 10579 | else if (!strcmp ("private" , p)) |
| 10580 | result = PRAGMA_OMP_CLAUSE_PRIVATE; |
| 10581 | else if (!strcmp ("proc_bind" , p)) |
| 10582 | result = PRAGMA_OMP_CLAUSE_PROC_BIND; |
| 10583 | break; |
| 10584 | case 'r': |
| 10585 | if (!strcmp ("reduction" , p)) |
| 10586 | result = PRAGMA_OMP_CLAUSE_REDUCTION; |
| 10587 | break; |
| 10588 | case 's': |
| 10589 | if (!strcmp ("safelen" , p)) |
| 10590 | result = PRAGMA_OMP_CLAUSE_SAFELEN; |
| 10591 | else if (!strcmp ("schedule" , p)) |
| 10592 | result = PRAGMA_OMP_CLAUSE_SCHEDULE; |
| 10593 | else if (!strcmp ("sections" , p)) |
| 10594 | result = PRAGMA_OMP_CLAUSE_SECTIONS; |
| 10595 | else if (!strcmp ("seq" , p)) |
| 10596 | result = PRAGMA_OACC_CLAUSE_SEQ; |
| 10597 | else if (!strcmp ("shared" , p)) |
| 10598 | result = PRAGMA_OMP_CLAUSE_SHARED; |
| 10599 | else if (!strcmp ("simd" , p)) |
| 10600 | result = PRAGMA_OMP_CLAUSE_SIMD; |
| 10601 | else if (!strcmp ("simdlen" , p)) |
| 10602 | result = PRAGMA_OMP_CLAUSE_SIMDLEN; |
| 10603 | else if (!strcmp ("self" , p)) |
| 10604 | result = PRAGMA_OACC_CLAUSE_SELF; |
| 10605 | break; |
| 10606 | case 't': |
| 10607 | if (!strcmp ("taskgroup" , p)) |
| 10608 | result = PRAGMA_OMP_CLAUSE_TASKGROUP; |
| 10609 | else if (!strcmp ("thread_limit" , p)) |
| 10610 | result = PRAGMA_OMP_CLAUSE_THREAD_LIMIT; |
| 10611 | else if (!strcmp ("threads" , p)) |
| 10612 | result = PRAGMA_OMP_CLAUSE_THREADS; |
| 10613 | else if (!strcmp ("tile" , p)) |
| 10614 | result = PRAGMA_OACC_CLAUSE_TILE; |
| 10615 | else if (!strcmp ("to" , p)) |
| 10616 | result = PRAGMA_OMP_CLAUSE_TO; |
| 10617 | break; |
| 10618 | case 'u': |
| 10619 | if (!strcmp ("uniform" , p)) |
| 10620 | result = PRAGMA_OMP_CLAUSE_UNIFORM; |
| 10621 | else if (!strcmp ("untied" , p)) |
| 10622 | result = PRAGMA_OMP_CLAUSE_UNTIED; |
| 10623 | else if (!strcmp ("use_device" , p)) |
| 10624 | result = PRAGMA_OACC_CLAUSE_USE_DEVICE; |
| 10625 | else if (!strcmp ("use_device_ptr" , p)) |
| 10626 | result = PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR; |
| 10627 | break; |
| 10628 | case 'v': |
| 10629 | if (!strcmp ("vector" , p)) |
| 10630 | result = PRAGMA_OACC_CLAUSE_VECTOR; |
| 10631 | else if (!strcmp ("vector_length" , p)) |
| 10632 | result = PRAGMA_OACC_CLAUSE_VECTOR_LENGTH; |
| 10633 | else if (flag_cilkplus && !strcmp ("vectorlength" , p)) |
| 10634 | result = PRAGMA_CILK_CLAUSE_VECTORLENGTH; |
| 10635 | break; |
| 10636 | case 'w': |
| 10637 | if (!strcmp ("wait" , p)) |
| 10638 | result = PRAGMA_OACC_CLAUSE_WAIT; |
| 10639 | else if (!strcmp ("worker" , p)) |
| 10640 | result = PRAGMA_OACC_CLAUSE_WORKER; |
| 10641 | break; |
| 10642 | } |
| 10643 | } |
| 10644 | |
| 10645 | if (result != PRAGMA_OMP_CLAUSE_NONE) |
| 10646 | c_parser_consume_token (parser); |
| 10647 | |
| 10648 | return result; |
| 10649 | } |
| 10650 | |
| 10651 | /* Validate that a clause of the given type does not already exist. */ |
| 10652 | |
| 10653 | static void |
| 10654 | check_no_duplicate_clause (tree clauses, enum omp_clause_code code, |
| 10655 | const char *name) |
| 10656 | { |
| 10657 | tree c; |
| 10658 | |
| 10659 | for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c)) |
| 10660 | if (OMP_CLAUSE_CODE (c) == code) |
| 10661 | { |
| 10662 | location_t loc = OMP_CLAUSE_LOCATION (c); |
| 10663 | error_at (loc, "too many %qs clauses" , name); |
| 10664 | break; |
| 10665 | } |
| 10666 | } |
| 10667 | |
| 10668 | /* OpenACC 2.0 |
| 10669 | Parse wait clause or wait directive parameters. */ |
| 10670 | |
| 10671 | static tree |
| 10672 | c_parser_oacc_wait_list (c_parser *parser, location_t clause_loc, tree list) |
| 10673 | { |
| 10674 | vec<tree, va_gc> *args; |
| 10675 | tree t, args_tree; |
| 10676 | |
| 10677 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 10678 | return list; |
| 10679 | |
| 10680 | args = c_parser_expr_list (parser, false, true, NULL, NULL, NULL, NULL); |
| 10681 | |
| 10682 | if (args->length () == 0) |
| 10683 | { |
| 10684 | c_parser_error (parser, "expected integer expression before ')'" ); |
| 10685 | release_tree_vector (args); |
| 10686 | return list; |
| 10687 | } |
| 10688 | |
| 10689 | args_tree = build_tree_list_vec (args); |
| 10690 | |
| 10691 | for (t = args_tree; t; t = TREE_CHAIN (t)) |
| 10692 | { |
| 10693 | tree targ = TREE_VALUE (t); |
| 10694 | |
| 10695 | if (targ != error_mark_node) |
| 10696 | { |
| 10697 | if (!INTEGRAL_TYPE_P (TREE_TYPE (targ))) |
| 10698 | { |
| 10699 | c_parser_error (parser, "expression must be integral" ); |
| 10700 | targ = error_mark_node; |
| 10701 | } |
| 10702 | else |
| 10703 | { |
| 10704 | tree c = build_omp_clause (clause_loc, OMP_CLAUSE_WAIT); |
| 10705 | |
| 10706 | OMP_CLAUSE_DECL (c) = targ; |
| 10707 | OMP_CLAUSE_CHAIN (c) = list; |
| 10708 | list = c; |
| 10709 | } |
| 10710 | } |
| 10711 | } |
| 10712 | |
| 10713 | release_tree_vector (args); |
| 10714 | c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 10715 | return list; |
| 10716 | } |
| 10717 | |
| 10718 | /* OpenACC 2.0, OpenMP 2.5: |
| 10719 | variable-list: |
| 10720 | identifier |
| 10721 | variable-list , identifier |
| 10722 | |
| 10723 | If KIND is nonzero, create the appropriate node and install the |
| 10724 | decl in OMP_CLAUSE_DECL and add the node to the head of the list. |
| 10725 | If KIND is nonzero, CLAUSE_LOC is the location of the clause. |
| 10726 | |
| 10727 | If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE; |
| 10728 | return the list created. */ |
| 10729 | |
| 10730 | static tree |
| 10731 | c_parser_omp_variable_list (c_parser *parser, |
| 10732 | location_t clause_loc, |
| 10733 | enum omp_clause_code kind, tree list) |
| 10734 | { |
| 10735 | if (c_parser_next_token_is_not (parser, CPP_NAME) |
| 10736 | || c_parser_peek_token (parser)->id_kind != C_ID_ID) |
| 10737 | c_parser_error (parser, "expected identifier" ); |
| 10738 | |
| 10739 | while (c_parser_next_token_is (parser, CPP_NAME) |
| 10740 | && c_parser_peek_token (parser)->id_kind == C_ID_ID) |
| 10741 | { |
| 10742 | tree t = lookup_name (c_parser_peek_token (parser)->value); |
| 10743 | |
| 10744 | if (t == NULL_TREE) |
| 10745 | { |
| 10746 | undeclared_variable (c_parser_peek_token (parser)->location, |
| 10747 | c_parser_peek_token (parser)->value); |
| 10748 | t = error_mark_node; |
| 10749 | } |
| 10750 | |
| 10751 | c_parser_consume_token (parser); |
| 10752 | |
| 10753 | if (t == error_mark_node) |
| 10754 | ; |
| 10755 | else if (kind != 0) |
| 10756 | { |
| 10757 | switch (kind) |
| 10758 | { |
| 10759 | case OMP_CLAUSE__CACHE_: |
| 10760 | /* The OpenACC cache directive explicitly only allows "array |
| 10761 | elements or subarrays". */ |
| 10762 | if (c_parser_peek_token (parser)->type != CPP_OPEN_SQUARE) |
| 10763 | { |
| 10764 | c_parser_error (parser, "expected %<[%>" ); |
| 10765 | t = error_mark_node; |
| 10766 | break; |
| 10767 | } |
| 10768 | /* FALLTHROUGH */ |
| 10769 | case OMP_CLAUSE_MAP: |
| 10770 | case OMP_CLAUSE_FROM: |
| 10771 | case OMP_CLAUSE_TO: |
| 10772 | while (c_parser_next_token_is (parser, CPP_DOT)) |
| 10773 | { |
| 10774 | location_t op_loc = c_parser_peek_token (parser)->location; |
| 10775 | c_parser_consume_token (parser); |
| 10776 | if (!c_parser_next_token_is (parser, CPP_NAME)) |
| 10777 | { |
| 10778 | c_parser_error (parser, "expected identifier" ); |
| 10779 | t = error_mark_node; |
| 10780 | break; |
| 10781 | } |
| 10782 | |
| 10783 | c_token *comp_tok = c_parser_peek_token (parser); |
| 10784 | tree ident = comp_tok->value; |
| 10785 | location_t comp_loc = comp_tok->location; |
| 10786 | c_parser_consume_token (parser); |
| 10787 | t = build_component_ref (op_loc, t, ident, comp_loc); |
| 10788 | } |
| 10789 | /* FALLTHROUGH */ |
| 10790 | case OMP_CLAUSE_DEPEND: |
| 10791 | case OMP_CLAUSE_REDUCTION: |
| 10792 | while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) |
| 10793 | { |
| 10794 | tree low_bound = NULL_TREE, length = NULL_TREE; |
| 10795 | |
| 10796 | c_parser_consume_token (parser); |
| 10797 | if (!c_parser_next_token_is (parser, CPP_COLON)) |
| 10798 | { |
| 10799 | location_t expr_loc |
| 10800 | = c_parser_peek_token (parser)->location; |
| 10801 | c_expr expr = c_parser_expression (parser); |
| 10802 | expr = convert_lvalue_to_rvalue (expr_loc, expr, |
| 10803 | false, true); |
| 10804 | low_bound = expr.value; |
| 10805 | } |
| 10806 | if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) |
| 10807 | length = integer_one_node; |
| 10808 | else |
| 10809 | { |
| 10810 | /* Look for `:'. */ |
| 10811 | if (!c_parser_require (parser, CPP_COLON, |
| 10812 | "expected %<:%>" )) |
| 10813 | { |
| 10814 | t = error_mark_node; |
| 10815 | break; |
| 10816 | } |
| 10817 | if (!c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) |
| 10818 | { |
| 10819 | location_t expr_loc |
| 10820 | = c_parser_peek_token (parser)->location; |
| 10821 | c_expr expr = c_parser_expression (parser); |
| 10822 | expr = convert_lvalue_to_rvalue (expr_loc, expr, |
| 10823 | false, true); |
| 10824 | length = expr.value; |
| 10825 | } |
| 10826 | } |
| 10827 | /* Look for the closing `]'. */ |
| 10828 | if (!c_parser_require (parser, CPP_CLOSE_SQUARE, |
| 10829 | "expected %<]%>" )) |
| 10830 | { |
| 10831 | t = error_mark_node; |
| 10832 | break; |
| 10833 | } |
| 10834 | |
| 10835 | t = tree_cons (low_bound, length, t); |
| 10836 | } |
| 10837 | break; |
| 10838 | default: |
| 10839 | break; |
| 10840 | } |
| 10841 | |
| 10842 | if (t != error_mark_node) |
| 10843 | { |
| 10844 | tree u = build_omp_clause (clause_loc, kind); |
| 10845 | OMP_CLAUSE_DECL (u) = t; |
| 10846 | OMP_CLAUSE_CHAIN (u) = list; |
| 10847 | list = u; |
| 10848 | } |
| 10849 | } |
| 10850 | else |
| 10851 | list = tree_cons (t, NULL_TREE, list); |
| 10852 | |
| 10853 | if (c_parser_next_token_is_not (parser, CPP_COMMA)) |
| 10854 | break; |
| 10855 | |
| 10856 | c_parser_consume_token (parser); |
| 10857 | } |
| 10858 | |
| 10859 | return list; |
| 10860 | } |
| 10861 | |
| 10862 | /* Similarly, but expect leading and trailing parenthesis. This is a very |
| 10863 | common case for OpenACC and OpenMP clauses. */ |
| 10864 | |
| 10865 | static tree |
| 10866 | c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind, |
| 10867 | tree list) |
| 10868 | { |
| 10869 | /* The clauses location. */ |
| 10870 | location_t loc = c_parser_peek_token (parser)->location; |
| 10871 | |
| 10872 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 10873 | { |
| 10874 | list = c_parser_omp_variable_list (parser, loc, kind, list); |
| 10875 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 10876 | } |
| 10877 | return list; |
| 10878 | } |
| 10879 | |
| 10880 | /* OpenACC 2.0: |
| 10881 | copy ( variable-list ) |
| 10882 | copyin ( variable-list ) |
| 10883 | copyout ( variable-list ) |
| 10884 | create ( variable-list ) |
| 10885 | delete ( variable-list ) |
| 10886 | present ( variable-list ) |
| 10887 | present_or_copy ( variable-list ) |
| 10888 | pcopy ( variable-list ) |
| 10889 | present_or_copyin ( variable-list ) |
| 10890 | pcopyin ( variable-list ) |
| 10891 | present_or_copyout ( variable-list ) |
| 10892 | pcopyout ( variable-list ) |
| 10893 | present_or_create ( variable-list ) |
| 10894 | pcreate ( variable-list ) */ |
| 10895 | |
| 10896 | static tree |
| 10897 | c_parser_oacc_data_clause (c_parser *parser, pragma_omp_clause c_kind, |
| 10898 | tree list) |
| 10899 | { |
| 10900 | enum gomp_map_kind kind; |
| 10901 | switch (c_kind) |
| 10902 | { |
| 10903 | case PRAGMA_OACC_CLAUSE_COPY: |
| 10904 | kind = GOMP_MAP_FORCE_TOFROM; |
| 10905 | break; |
| 10906 | case PRAGMA_OACC_CLAUSE_COPYIN: |
| 10907 | kind = GOMP_MAP_FORCE_TO; |
| 10908 | break; |
| 10909 | case PRAGMA_OACC_CLAUSE_COPYOUT: |
| 10910 | kind = GOMP_MAP_FORCE_FROM; |
| 10911 | break; |
| 10912 | case PRAGMA_OACC_CLAUSE_CREATE: |
| 10913 | kind = GOMP_MAP_FORCE_ALLOC; |
| 10914 | break; |
| 10915 | case PRAGMA_OACC_CLAUSE_DELETE: |
| 10916 | kind = GOMP_MAP_DELETE; |
| 10917 | break; |
| 10918 | case PRAGMA_OACC_CLAUSE_DEVICE: |
| 10919 | kind = GOMP_MAP_FORCE_TO; |
| 10920 | break; |
| 10921 | case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT: |
| 10922 | kind = GOMP_MAP_DEVICE_RESIDENT; |
| 10923 | break; |
| 10924 | case PRAGMA_OACC_CLAUSE_HOST: |
| 10925 | case PRAGMA_OACC_CLAUSE_SELF: |
| 10926 | kind = GOMP_MAP_FORCE_FROM; |
| 10927 | break; |
| 10928 | case PRAGMA_OACC_CLAUSE_LINK: |
| 10929 | kind = GOMP_MAP_LINK; |
| 10930 | break; |
| 10931 | case PRAGMA_OACC_CLAUSE_PRESENT: |
| 10932 | kind = GOMP_MAP_FORCE_PRESENT; |
| 10933 | break; |
| 10934 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY: |
| 10935 | kind = GOMP_MAP_TOFROM; |
| 10936 | break; |
| 10937 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN: |
| 10938 | kind = GOMP_MAP_TO; |
| 10939 | break; |
| 10940 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT: |
| 10941 | kind = GOMP_MAP_FROM; |
| 10942 | break; |
| 10943 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE: |
| 10944 | kind = GOMP_MAP_ALLOC; |
| 10945 | break; |
| 10946 | default: |
| 10947 | gcc_unreachable (); |
| 10948 | } |
| 10949 | tree nl, c; |
| 10950 | nl = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_MAP, list); |
| 10951 | |
| 10952 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
| 10953 | OMP_CLAUSE_SET_MAP_KIND (c, kind); |
| 10954 | |
| 10955 | return nl; |
| 10956 | } |
| 10957 | |
| 10958 | /* OpenACC 2.0: |
| 10959 | deviceptr ( variable-list ) */ |
| 10960 | |
| 10961 | static tree |
| 10962 | c_parser_oacc_data_clause_deviceptr (c_parser *parser, tree list) |
| 10963 | { |
| 10964 | location_t loc = c_parser_peek_token (parser)->location; |
| 10965 | tree vars, t; |
| 10966 | |
| 10967 | /* Can't use OMP_CLAUSE_MAP here (that is, can't use the generic |
| 10968 | c_parser_oacc_data_clause), as for PRAGMA_OACC_CLAUSE_DEVICEPTR, |
| 10969 | variable-list must only allow for pointer variables. */ |
| 10970 | vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); |
| 10971 | for (t = vars; t && t; t = TREE_CHAIN (t)) |
| 10972 | { |
| 10973 | tree v = TREE_PURPOSE (t); |
| 10974 | |
| 10975 | /* FIXME diagnostics: Ideally we should keep individual |
| 10976 | locations for all the variables in the var list to make the |
| 10977 | following errors more precise. Perhaps |
| 10978 | c_parser_omp_var_list_parens() should construct a list of |
| 10979 | locations to go along with the var list. */ |
| 10980 | |
| 10981 | if (!VAR_P (v) && TREE_CODE (v) != PARM_DECL) |
| 10982 | error_at (loc, "%qD is not a variable" , v); |
| 10983 | else if (TREE_TYPE (v) == error_mark_node) |
| 10984 | ; |
| 10985 | else if (!POINTER_TYPE_P (TREE_TYPE (v))) |
| 10986 | error_at (loc, "%qD is not a pointer variable" , v); |
| 10987 | |
| 10988 | tree u = build_omp_clause (loc, OMP_CLAUSE_MAP); |
| 10989 | OMP_CLAUSE_SET_MAP_KIND (u, GOMP_MAP_FORCE_DEVICEPTR); |
| 10990 | OMP_CLAUSE_DECL (u) = v; |
| 10991 | OMP_CLAUSE_CHAIN (u) = list; |
| 10992 | list = u; |
| 10993 | } |
| 10994 | |
| 10995 | return list; |
| 10996 | } |
| 10997 | |
| 10998 | /* OpenACC 2.0, OpenMP 3.0: |
| 10999 | collapse ( constant-expression ) */ |
| 11000 | |
| 11001 | static tree |
| 11002 | c_parser_omp_clause_collapse (c_parser *parser, tree list) |
| 11003 | { |
| 11004 | tree c, num = error_mark_node; |
| 11005 | HOST_WIDE_INT n; |
| 11006 | location_t loc; |
| 11007 | |
| 11008 | check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse" ); |
| 11009 | check_no_duplicate_clause (list, OMP_CLAUSE_TILE, "tile" ); |
| 11010 | |
| 11011 | loc = c_parser_peek_token (parser)->location; |
| 11012 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 11013 | { |
| 11014 | num = c_parser_expr_no_commas (parser, NULL).value; |
| 11015 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 11016 | } |
| 11017 | if (num == error_mark_node) |
| 11018 | return list; |
| 11019 | mark_exp_read (num); |
| 11020 | num = c_fully_fold (num, false, NULL); |
| 11021 | if (!INTEGRAL_TYPE_P (TREE_TYPE (num)) |
| 11022 | || !tree_fits_shwi_p (num) |
| 11023 | || (n = tree_to_shwi (num)) <= 0 |
| 11024 | || (int) n != n) |
| 11025 | { |
| 11026 | error_at (loc, |
| 11027 | "collapse argument needs positive constant integer expression" ); |
| 11028 | return list; |
| 11029 | } |
| 11030 | c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE); |
| 11031 | OMP_CLAUSE_COLLAPSE_EXPR (c) = num; |
| 11032 | OMP_CLAUSE_CHAIN (c) = list; |
| 11033 | return c; |
| 11034 | } |
| 11035 | |
| 11036 | /* OpenMP 2.5: |
| 11037 | copyin ( variable-list ) */ |
| 11038 | |
| 11039 | static tree |
| 11040 | c_parser_omp_clause_copyin (c_parser *parser, tree list) |
| 11041 | { |
| 11042 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list); |
| 11043 | } |
| 11044 | |
| 11045 | /* OpenMP 2.5: |
| 11046 | copyprivate ( variable-list ) */ |
| 11047 | |
| 11048 | static tree |
| 11049 | c_parser_omp_clause_copyprivate (c_parser *parser, tree list) |
| 11050 | { |
| 11051 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list); |
| 11052 | } |
| 11053 | |
| 11054 | /* OpenMP 2.5: |
| 11055 | default ( shared | none ) |
| 11056 | |
| 11057 | OpenACC 2.0: |
| 11058 | default (none) */ |
| 11059 | |
| 11060 | static tree |
| 11061 | c_parser_omp_clause_default (c_parser *parser, tree list, bool is_oacc) |
| 11062 | { |
| 11063 | enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED; |
| 11064 | location_t loc = c_parser_peek_token (parser)->location; |
| 11065 | tree c; |
| 11066 | |
| 11067 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 11068 | return list; |
| 11069 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 11070 | { |
| 11071 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 11072 | |
| 11073 | switch (p[0]) |
| 11074 | { |
| 11075 | case 'n': |
| 11076 | if (strcmp ("none" , p) != 0) |
| 11077 | goto invalid_kind; |
| 11078 | kind = OMP_CLAUSE_DEFAULT_NONE; |
| 11079 | break; |
| 11080 | |
| 11081 | case 's': |
| 11082 | if (strcmp ("shared" , p) != 0 || is_oacc) |
| 11083 | goto invalid_kind; |
| 11084 | kind = OMP_CLAUSE_DEFAULT_SHARED; |
| 11085 | break; |
| 11086 | |
| 11087 | default: |
| 11088 | goto invalid_kind; |
| 11089 | } |
| 11090 | |
| 11091 | c_parser_consume_token (parser); |
| 11092 | } |
| 11093 | else |
| 11094 | { |
| 11095 | invalid_kind: |
| 11096 | if (is_oacc) |
| 11097 | c_parser_error (parser, "expected %<none%>" ); |
| 11098 | else |
| 11099 | c_parser_error (parser, "expected %<none%> or %<shared%>" ); |
| 11100 | } |
| 11101 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 11102 | |
| 11103 | if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED) |
| 11104 | return list; |
| 11105 | |
| 11106 | check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default" ); |
| 11107 | c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT); |
| 11108 | OMP_CLAUSE_CHAIN (c) = list; |
| 11109 | OMP_CLAUSE_DEFAULT_KIND (c) = kind; |
| 11110 | |
| 11111 | return c; |
| 11112 | } |
| 11113 | |
| 11114 | /* OpenMP 2.5: |
| 11115 | firstprivate ( variable-list ) */ |
| 11116 | |
| 11117 | static tree |
| 11118 | c_parser_omp_clause_firstprivate (c_parser *parser, tree list) |
| 11119 | { |
| 11120 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list); |
| 11121 | } |
| 11122 | |
| 11123 | /* OpenMP 3.1: |
| 11124 | final ( expression ) */ |
| 11125 | |
| 11126 | static tree |
| 11127 | c_parser_omp_clause_final (c_parser *parser, tree list) |
| 11128 | { |
| 11129 | location_t loc = c_parser_peek_token (parser)->location; |
| 11130 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 11131 | { |
| 11132 | tree t = c_parser_paren_condition (parser); |
| 11133 | tree c; |
| 11134 | |
| 11135 | check_no_duplicate_clause (list, OMP_CLAUSE_FINAL, "final" ); |
| 11136 | |
| 11137 | c = build_omp_clause (loc, OMP_CLAUSE_FINAL); |
| 11138 | OMP_CLAUSE_FINAL_EXPR (c) = t; |
| 11139 | OMP_CLAUSE_CHAIN (c) = list; |
| 11140 | list = c; |
| 11141 | } |
| 11142 | else |
| 11143 | c_parser_error (parser, "expected %<(%>" ); |
| 11144 | |
| 11145 | return list; |
| 11146 | } |
| 11147 | |
| 11148 | /* OpenACC, OpenMP 2.5: |
| 11149 | if ( expression ) |
| 11150 | |
| 11151 | OpenMP 4.5: |
| 11152 | if ( directive-name-modifier : expression ) |
| 11153 | |
| 11154 | directive-name-modifier: |
| 11155 | parallel | task | taskloop | target data | target | target update |
| 11156 | | target enter data | target exit data */ |
| 11157 | |
| 11158 | static tree |
| 11159 | c_parser_omp_clause_if (c_parser *parser, tree list, bool is_omp) |
| 11160 | { |
| 11161 | location_t location = c_parser_peek_token (parser)->location; |
| 11162 | enum tree_code if_modifier = ERROR_MARK; |
| 11163 | |
| 11164 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 11165 | return list; |
| 11166 | |
| 11167 | if (is_omp && c_parser_next_token_is (parser, CPP_NAME)) |
| 11168 | { |
| 11169 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 11170 | int n = 2; |
| 11171 | if (strcmp (p, "parallel" ) == 0) |
| 11172 | if_modifier = OMP_PARALLEL; |
| 11173 | else if (strcmp (p, "task" ) == 0) |
| 11174 | if_modifier = OMP_TASK; |
| 11175 | else if (strcmp (p, "taskloop" ) == 0) |
| 11176 | if_modifier = OMP_TASKLOOP; |
| 11177 | else if (strcmp (p, "target" ) == 0) |
| 11178 | { |
| 11179 | if_modifier = OMP_TARGET; |
| 11180 | if (c_parser_peek_2nd_token (parser)->type == CPP_NAME) |
| 11181 | { |
| 11182 | p = IDENTIFIER_POINTER (c_parser_peek_2nd_token (parser)->value); |
| 11183 | if (strcmp ("data" , p) == 0) |
| 11184 | if_modifier = OMP_TARGET_DATA; |
| 11185 | else if (strcmp ("update" , p) == 0) |
| 11186 | if_modifier = OMP_TARGET_UPDATE; |
| 11187 | else if (strcmp ("enter" , p) == 0) |
| 11188 | if_modifier = OMP_TARGET_ENTER_DATA; |
| 11189 | else if (strcmp ("exit" , p) == 0) |
| 11190 | if_modifier = OMP_TARGET_EXIT_DATA; |
| 11191 | if (if_modifier != OMP_TARGET) |
| 11192 | { |
| 11193 | n = 3; |
| 11194 | c_parser_consume_token (parser); |
| 11195 | } |
| 11196 | else |
| 11197 | { |
| 11198 | location_t loc = c_parser_peek_2nd_token (parser)->location; |
| 11199 | error_at (loc, "expected %<data%>, %<update%>, %<enter%> " |
| 11200 | "or %<exit%>" ); |
| 11201 | if_modifier = ERROR_MARK; |
| 11202 | } |
| 11203 | if (if_modifier == OMP_TARGET_ENTER_DATA |
| 11204 | || if_modifier == OMP_TARGET_EXIT_DATA) |
| 11205 | { |
| 11206 | if (c_parser_peek_2nd_token (parser)->type == CPP_NAME) |
| 11207 | { |
| 11208 | p = IDENTIFIER_POINTER |
| 11209 | (c_parser_peek_2nd_token (parser)->value); |
| 11210 | if (strcmp ("data" , p) == 0) |
| 11211 | n = 4; |
| 11212 | } |
| 11213 | if (n == 4) |
| 11214 | c_parser_consume_token (parser); |
| 11215 | else |
| 11216 | { |
| 11217 | location_t loc |
| 11218 | = c_parser_peek_2nd_token (parser)->location; |
| 11219 | error_at (loc, "expected %<data%>" ); |
| 11220 | if_modifier = ERROR_MARK; |
| 11221 | } |
| 11222 | } |
| 11223 | } |
| 11224 | } |
| 11225 | if (if_modifier != ERROR_MARK) |
| 11226 | { |
| 11227 | if (c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 11228 | { |
| 11229 | c_parser_consume_token (parser); |
| 11230 | c_parser_consume_token (parser); |
| 11231 | } |
| 11232 | else |
| 11233 | { |
| 11234 | if (n > 2) |
| 11235 | { |
| 11236 | location_t loc = c_parser_peek_2nd_token (parser)->location; |
| 11237 | error_at (loc, "expected %<:%>" ); |
| 11238 | } |
| 11239 | if_modifier = ERROR_MARK; |
| 11240 | } |
| 11241 | } |
| 11242 | } |
| 11243 | |
| 11244 | tree t = c_parser_condition (parser), c; |
| 11245 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 11246 | |
| 11247 | for (c = list; c ; c = OMP_CLAUSE_CHAIN (c)) |
| 11248 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_IF) |
| 11249 | { |
| 11250 | if (if_modifier != ERROR_MARK |
| 11251 | && OMP_CLAUSE_IF_MODIFIER (c) == if_modifier) |
| 11252 | { |
| 11253 | const char *p = NULL; |
| 11254 | switch (if_modifier) |
| 11255 | { |
| 11256 | case OMP_PARALLEL: p = "parallel" ; break; |
| 11257 | case OMP_TASK: p = "task" ; break; |
| 11258 | case OMP_TASKLOOP: p = "taskloop" ; break; |
| 11259 | case OMP_TARGET_DATA: p = "target data" ; break; |
| 11260 | case OMP_TARGET: p = "target" ; break; |
| 11261 | case OMP_TARGET_UPDATE: p = "target update" ; break; |
| 11262 | case OMP_TARGET_ENTER_DATA: p = "enter data" ; break; |
| 11263 | case OMP_TARGET_EXIT_DATA: p = "exit data" ; break; |
| 11264 | default: gcc_unreachable (); |
| 11265 | } |
| 11266 | error_at (location, "too many %<if%> clauses with %qs modifier" , |
| 11267 | p); |
| 11268 | return list; |
| 11269 | } |
| 11270 | else if (OMP_CLAUSE_IF_MODIFIER (c) == if_modifier) |
| 11271 | { |
| 11272 | if (!is_omp) |
| 11273 | error_at (location, "too many %<if%> clauses" ); |
| 11274 | else |
| 11275 | error_at (location, "too many %<if%> clauses without modifier" ); |
| 11276 | return list; |
| 11277 | } |
| 11278 | else if (if_modifier == ERROR_MARK |
| 11279 | || OMP_CLAUSE_IF_MODIFIER (c) == ERROR_MARK) |
| 11280 | { |
| 11281 | error_at (location, "if any %<if%> clause has modifier, then all " |
| 11282 | "%<if%> clauses have to use modifier" ); |
| 11283 | return list; |
| 11284 | } |
| 11285 | } |
| 11286 | |
| 11287 | c = build_omp_clause (location, OMP_CLAUSE_IF); |
| 11288 | OMP_CLAUSE_IF_MODIFIER (c) = if_modifier; |
| 11289 | OMP_CLAUSE_IF_EXPR (c) = t; |
| 11290 | OMP_CLAUSE_CHAIN (c) = list; |
| 11291 | return c; |
| 11292 | } |
| 11293 | |
| 11294 | /* OpenMP 2.5: |
| 11295 | lastprivate ( variable-list ) */ |
| 11296 | |
| 11297 | static tree |
| 11298 | c_parser_omp_clause_lastprivate (c_parser *parser, tree list) |
| 11299 | { |
| 11300 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list); |
| 11301 | } |
| 11302 | |
| 11303 | /* OpenMP 3.1: |
| 11304 | mergeable */ |
| 11305 | |
| 11306 | static tree |
| 11307 | c_parser_omp_clause_mergeable (c_parser *parser ATTRIBUTE_UNUSED, tree list) |
| 11308 | { |
| 11309 | tree c; |
| 11310 | |
| 11311 | /* FIXME: Should we allow duplicates? */ |
| 11312 | check_no_duplicate_clause (list, OMP_CLAUSE_MERGEABLE, "mergeable" ); |
| 11313 | |
| 11314 | c = build_omp_clause (c_parser_peek_token (parser)->location, |
| 11315 | OMP_CLAUSE_MERGEABLE); |
| 11316 | OMP_CLAUSE_CHAIN (c) = list; |
| 11317 | |
| 11318 | return c; |
| 11319 | } |
| 11320 | |
| 11321 | /* OpenMP 2.5: |
| 11322 | nowait */ |
| 11323 | |
| 11324 | static tree |
| 11325 | c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list) |
| 11326 | { |
| 11327 | tree c; |
| 11328 | location_t loc = c_parser_peek_token (parser)->location; |
| 11329 | |
| 11330 | check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait" ); |
| 11331 | |
| 11332 | c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT); |
| 11333 | OMP_CLAUSE_CHAIN (c) = list; |
| 11334 | return c; |
| 11335 | } |
| 11336 | |
| 11337 | /* OpenACC: |
| 11338 | num_gangs ( expression ) */ |
| 11339 | |
| 11340 | static tree |
| 11341 | c_parser_omp_clause_num_gangs (c_parser *parser, tree list) |
| 11342 | { |
| 11343 | location_t num_gangs_loc = c_parser_peek_token (parser)->location; |
| 11344 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 11345 | { |
| 11346 | location_t expr_loc = c_parser_peek_token (parser)->location; |
| 11347 | c_expr expr = c_parser_expression (parser); |
| 11348 | expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 11349 | tree c, t = expr.value; |
| 11350 | t = c_fully_fold (t, false, NULL); |
| 11351 | |
| 11352 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 11353 | |
| 11354 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 11355 | { |
| 11356 | c_parser_error (parser, "expected integer expression" ); |
| 11357 | return list; |
| 11358 | } |
| 11359 | |
| 11360 | /* Attempt to statically determine when the number isn't positive. */ |
| 11361 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, |
| 11362 | build_int_cst (TREE_TYPE (t), 0)); |
| 11363 | protected_set_expr_location (c, expr_loc); |
| 11364 | if (c == boolean_true_node) |
| 11365 | { |
| 11366 | warning_at (expr_loc, 0, |
| 11367 | "%<num_gangs%> value must be positive" ); |
| 11368 | t = integer_one_node; |
| 11369 | } |
| 11370 | |
| 11371 | check_no_duplicate_clause (list, OMP_CLAUSE_NUM_GANGS, "num_gangs" ); |
| 11372 | |
| 11373 | c = build_omp_clause (num_gangs_loc, OMP_CLAUSE_NUM_GANGS); |
| 11374 | OMP_CLAUSE_NUM_GANGS_EXPR (c) = t; |
| 11375 | OMP_CLAUSE_CHAIN (c) = list; |
| 11376 | list = c; |
| 11377 | } |
| 11378 | |
| 11379 | return list; |
| 11380 | } |
| 11381 | |
| 11382 | /* OpenMP 2.5: |
| 11383 | num_threads ( expression ) */ |
| 11384 | |
| 11385 | static tree |
| 11386 | c_parser_omp_clause_num_threads (c_parser *parser, tree list) |
| 11387 | { |
| 11388 | location_t num_threads_loc = c_parser_peek_token (parser)->location; |
| 11389 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 11390 | { |
| 11391 | location_t expr_loc = c_parser_peek_token (parser)->location; |
| 11392 | c_expr expr = c_parser_expression (parser); |
| 11393 | expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 11394 | tree c, t = expr.value; |
| 11395 | t = c_fully_fold (t, false, NULL); |
| 11396 | |
| 11397 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 11398 | |
| 11399 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 11400 | { |
| 11401 | c_parser_error (parser, "expected integer expression" ); |
| 11402 | return list; |
| 11403 | } |
| 11404 | |
| 11405 | /* Attempt to statically determine when the number isn't positive. */ |
| 11406 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, |
| 11407 | build_int_cst (TREE_TYPE (t), 0)); |
| 11408 | protected_set_expr_location (c, expr_loc); |
| 11409 | if (c == boolean_true_node) |
| 11410 | { |
| 11411 | warning_at (expr_loc, 0, |
| 11412 | "%<num_threads%> value must be positive" ); |
| 11413 | t = integer_one_node; |
| 11414 | } |
| 11415 | |
| 11416 | check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads" ); |
| 11417 | |
| 11418 | c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS); |
| 11419 | OMP_CLAUSE_NUM_THREADS_EXPR (c) = t; |
| 11420 | OMP_CLAUSE_CHAIN (c) = list; |
| 11421 | list = c; |
| 11422 | } |
| 11423 | |
| 11424 | return list; |
| 11425 | } |
| 11426 | |
| 11427 | /* OpenMP 4.5: |
| 11428 | num_tasks ( expression ) */ |
| 11429 | |
| 11430 | static tree |
| 11431 | c_parser_omp_clause_num_tasks (c_parser *parser, tree list) |
| 11432 | { |
| 11433 | location_t num_tasks_loc = c_parser_peek_token (parser)->location; |
| 11434 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 11435 | { |
| 11436 | location_t expr_loc = c_parser_peek_token (parser)->location; |
| 11437 | c_expr expr = c_parser_expression (parser); |
| 11438 | expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 11439 | tree c, t = expr.value; |
| 11440 | t = c_fully_fold (t, false, NULL); |
| 11441 | |
| 11442 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 11443 | |
| 11444 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 11445 | { |
| 11446 | c_parser_error (parser, "expected integer expression" ); |
| 11447 | return list; |
| 11448 | } |
| 11449 | |
| 11450 | /* Attempt to statically determine when the number isn't positive. */ |
| 11451 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, |
| 11452 | build_int_cst (TREE_TYPE (t), 0)); |
| 11453 | if (CAN_HAVE_LOCATION_P (c)) |
| 11454 | SET_EXPR_LOCATION (c, expr_loc); |
| 11455 | if (c == boolean_true_node) |
| 11456 | { |
| 11457 | warning_at (expr_loc, 0, "%<num_tasks%> value must be positive" ); |
| 11458 | t = integer_one_node; |
| 11459 | } |
| 11460 | |
| 11461 | check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TASKS, "num_tasks" ); |
| 11462 | |
| 11463 | c = build_omp_clause (num_tasks_loc, OMP_CLAUSE_NUM_TASKS); |
| 11464 | OMP_CLAUSE_NUM_TASKS_EXPR (c) = t; |
| 11465 | OMP_CLAUSE_CHAIN (c) = list; |
| 11466 | list = c; |
| 11467 | } |
| 11468 | |
| 11469 | return list; |
| 11470 | } |
| 11471 | |
| 11472 | /* OpenMP 4.5: |
| 11473 | grainsize ( expression ) */ |
| 11474 | |
| 11475 | static tree |
| 11476 | c_parser_omp_clause_grainsize (c_parser *parser, tree list) |
| 11477 | { |
| 11478 | location_t grainsize_loc = c_parser_peek_token (parser)->location; |
| 11479 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 11480 | { |
| 11481 | location_t expr_loc = c_parser_peek_token (parser)->location; |
| 11482 | c_expr expr = c_parser_expression (parser); |
| 11483 | expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 11484 | tree c, t = expr.value; |
| 11485 | t = c_fully_fold (t, false, NULL); |
| 11486 | |
| 11487 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 11488 | |
| 11489 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 11490 | { |
| 11491 | c_parser_error (parser, "expected integer expression" ); |
| 11492 | return list; |
| 11493 | } |
| 11494 | |
| 11495 | /* Attempt to statically determine when the number isn't positive. */ |
| 11496 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, |
| 11497 | build_int_cst (TREE_TYPE (t), 0)); |
| 11498 | if (CAN_HAVE_LOCATION_P (c)) |
| 11499 | SET_EXPR_LOCATION (c, expr_loc); |
| 11500 | if (c == boolean_true_node) |
| 11501 | { |
| 11502 | warning_at (expr_loc, 0, "%<grainsize%> value must be positive" ); |
| 11503 | t = integer_one_node; |
| 11504 | } |
| 11505 | |
| 11506 | check_no_duplicate_clause (list, OMP_CLAUSE_GRAINSIZE, "grainsize" ); |
| 11507 | |
| 11508 | c = build_omp_clause (grainsize_loc, OMP_CLAUSE_GRAINSIZE); |
| 11509 | OMP_CLAUSE_GRAINSIZE_EXPR (c) = t; |
| 11510 | OMP_CLAUSE_CHAIN (c) = list; |
| 11511 | list = c; |
| 11512 | } |
| 11513 | |
| 11514 | return list; |
| 11515 | } |
| 11516 | |
| 11517 | /* OpenMP 4.5: |
| 11518 | priority ( expression ) */ |
| 11519 | |
| 11520 | static tree |
| 11521 | c_parser_omp_clause_priority (c_parser *parser, tree list) |
| 11522 | { |
| 11523 | location_t priority_loc = c_parser_peek_token (parser)->location; |
| 11524 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 11525 | { |
| 11526 | location_t expr_loc = c_parser_peek_token (parser)->location; |
| 11527 | c_expr expr = c_parser_expression (parser); |
| 11528 | expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 11529 | tree c, t = expr.value; |
| 11530 | t = c_fully_fold (t, false, NULL); |
| 11531 | |
| 11532 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 11533 | |
| 11534 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 11535 | { |
| 11536 | c_parser_error (parser, "expected integer expression" ); |
| 11537 | return list; |
| 11538 | } |
| 11539 | |
| 11540 | /* Attempt to statically determine when the number isn't |
| 11541 | non-negative. */ |
| 11542 | c = fold_build2_loc (expr_loc, LT_EXPR, boolean_type_node, t, |
| 11543 | build_int_cst (TREE_TYPE (t), 0)); |
| 11544 | if (CAN_HAVE_LOCATION_P (c)) |
| 11545 | SET_EXPR_LOCATION (c, expr_loc); |
| 11546 | if (c == boolean_true_node) |
| 11547 | { |
| 11548 | warning_at (expr_loc, 0, "%<priority%> value must be non-negative" ); |
| 11549 | t = integer_one_node; |
| 11550 | } |
| 11551 | |
| 11552 | check_no_duplicate_clause (list, OMP_CLAUSE_PRIORITY, "priority" ); |
| 11553 | |
| 11554 | c = build_omp_clause (priority_loc, OMP_CLAUSE_PRIORITY); |
| 11555 | OMP_CLAUSE_PRIORITY_EXPR (c) = t; |
| 11556 | OMP_CLAUSE_CHAIN (c) = list; |
| 11557 | list = c; |
| 11558 | } |
| 11559 | |
| 11560 | return list; |
| 11561 | } |
| 11562 | |
| 11563 | /* OpenMP 4.5: |
| 11564 | hint ( expression ) */ |
| 11565 | |
| 11566 | static tree |
| 11567 | c_parser_omp_clause_hint (c_parser *parser, tree list) |
| 11568 | { |
| 11569 | location_t hint_loc = c_parser_peek_token (parser)->location; |
| 11570 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 11571 | { |
| 11572 | location_t expr_loc = c_parser_peek_token (parser)->location; |
| 11573 | c_expr expr = c_parser_expression (parser); |
| 11574 | expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 11575 | tree c, t = expr.value; |
| 11576 | t = c_fully_fold (t, false, NULL); |
| 11577 | |
| 11578 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 11579 | |
| 11580 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 11581 | { |
| 11582 | c_parser_error (parser, "expected integer expression" ); |
| 11583 | return list; |
| 11584 | } |
| 11585 | |
| 11586 | check_no_duplicate_clause (list, OMP_CLAUSE_HINT, "hint" ); |
| 11587 | |
| 11588 | c = build_omp_clause (hint_loc, OMP_CLAUSE_HINT); |
| 11589 | OMP_CLAUSE_HINT_EXPR (c) = t; |
| 11590 | OMP_CLAUSE_CHAIN (c) = list; |
| 11591 | list = c; |
| 11592 | } |
| 11593 | |
| 11594 | return list; |
| 11595 | } |
| 11596 | |
| 11597 | /* OpenMP 4.5: |
| 11598 | defaultmap ( tofrom : scalar ) */ |
| 11599 | |
| 11600 | static tree |
| 11601 | c_parser_omp_clause_defaultmap (c_parser *parser, tree list) |
| 11602 | { |
| 11603 | location_t loc = c_parser_peek_token (parser)->location; |
| 11604 | tree c; |
| 11605 | const char *p; |
| 11606 | |
| 11607 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 11608 | return list; |
| 11609 | if (!c_parser_next_token_is (parser, CPP_NAME)) |
| 11610 | { |
| 11611 | c_parser_error (parser, "expected %<tofrom%>" ); |
| 11612 | goto out_err; |
| 11613 | } |
| 11614 | p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 11615 | if (strcmp (p, "tofrom" ) != 0) |
| 11616 | { |
| 11617 | c_parser_error (parser, "expected %<tofrom%>" ); |
| 11618 | goto out_err; |
| 11619 | } |
| 11620 | c_parser_consume_token (parser); |
| 11621 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>" )) |
| 11622 | goto out_err; |
| 11623 | if (!c_parser_next_token_is (parser, CPP_NAME)) |
| 11624 | { |
| 11625 | c_parser_error (parser, "expected %<scalar%>" ); |
| 11626 | goto out_err; |
| 11627 | } |
| 11628 | p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 11629 | if (strcmp (p, "scalar" ) != 0) |
| 11630 | { |
| 11631 | c_parser_error (parser, "expected %<scalar%>" ); |
| 11632 | goto out_err; |
| 11633 | } |
| 11634 | c_parser_consume_token (parser); |
| 11635 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 11636 | check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULTMAP, "defaultmap" ); |
| 11637 | c = build_omp_clause (loc, OMP_CLAUSE_DEFAULTMAP); |
| 11638 | OMP_CLAUSE_CHAIN (c) = list; |
| 11639 | return c; |
| 11640 | |
| 11641 | out_err: |
| 11642 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 11643 | return list; |
| 11644 | } |
| 11645 | |
| 11646 | /* OpenACC 2.0: |
| 11647 | use_device ( variable-list ) |
| 11648 | |
| 11649 | OpenMP 4.5: |
| 11650 | use_device_ptr ( variable-list ) */ |
| 11651 | |
| 11652 | static tree |
| 11653 | c_parser_omp_clause_use_device_ptr (c_parser *parser, tree list) |
| 11654 | { |
| 11655 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_USE_DEVICE_PTR, |
| 11656 | list); |
| 11657 | } |
| 11658 | |
| 11659 | /* OpenMP 4.5: |
| 11660 | is_device_ptr ( variable-list ) */ |
| 11661 | |
| 11662 | static tree |
| 11663 | c_parser_omp_clause_is_device_ptr (c_parser *parser, tree list) |
| 11664 | { |
| 11665 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_IS_DEVICE_PTR, list); |
| 11666 | } |
| 11667 | |
| 11668 | /* OpenACC: |
| 11669 | num_workers ( expression ) */ |
| 11670 | |
| 11671 | static tree |
| 11672 | c_parser_omp_clause_num_workers (c_parser *parser, tree list) |
| 11673 | { |
| 11674 | location_t num_workers_loc = c_parser_peek_token (parser)->location; |
| 11675 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 11676 | { |
| 11677 | location_t expr_loc = c_parser_peek_token (parser)->location; |
| 11678 | c_expr expr = c_parser_expression (parser); |
| 11679 | expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 11680 | tree c, t = expr.value; |
| 11681 | t = c_fully_fold (t, false, NULL); |
| 11682 | |
| 11683 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 11684 | |
| 11685 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 11686 | { |
| 11687 | c_parser_error (parser, "expected integer expression" ); |
| 11688 | return list; |
| 11689 | } |
| 11690 | |
| 11691 | /* Attempt to statically determine when the number isn't positive. */ |
| 11692 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, |
| 11693 | build_int_cst (TREE_TYPE (t), 0)); |
| 11694 | protected_set_expr_location (c, expr_loc); |
| 11695 | if (c == boolean_true_node) |
| 11696 | { |
| 11697 | warning_at (expr_loc, 0, |
| 11698 | "%<num_workers%> value must be positive" ); |
| 11699 | t = integer_one_node; |
| 11700 | } |
| 11701 | |
| 11702 | check_no_duplicate_clause (list, OMP_CLAUSE_NUM_WORKERS, "num_workers" ); |
| 11703 | |
| 11704 | c = build_omp_clause (num_workers_loc, OMP_CLAUSE_NUM_WORKERS); |
| 11705 | OMP_CLAUSE_NUM_WORKERS_EXPR (c) = t; |
| 11706 | OMP_CLAUSE_CHAIN (c) = list; |
| 11707 | list = c; |
| 11708 | } |
| 11709 | |
| 11710 | return list; |
| 11711 | } |
| 11712 | |
| 11713 | /* OpenACC: |
| 11714 | |
| 11715 | gang [( gang-arg-list )] |
| 11716 | worker [( [num:] int-expr )] |
| 11717 | vector [( [length:] int-expr )] |
| 11718 | |
| 11719 | where gang-arg is one of: |
| 11720 | |
| 11721 | [num:] int-expr |
| 11722 | static: size-expr |
| 11723 | |
| 11724 | and size-expr may be: |
| 11725 | |
| 11726 | * |
| 11727 | int-expr |
| 11728 | */ |
| 11729 | |
| 11730 | static tree |
| 11731 | c_parser_oacc_shape_clause (c_parser *parser, omp_clause_code kind, |
| 11732 | const char *str, tree list) |
| 11733 | { |
| 11734 | const char *id = "num" ; |
| 11735 | tree ops[2] = { NULL_TREE, NULL_TREE }, c; |
| 11736 | location_t loc = c_parser_peek_token (parser)->location; |
| 11737 | |
| 11738 | if (kind == OMP_CLAUSE_VECTOR) |
| 11739 | id = "length" ; |
| 11740 | |
| 11741 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 11742 | { |
| 11743 | c_parser_consume_token (parser); |
| 11744 | |
| 11745 | do |
| 11746 | { |
| 11747 | c_token *next = c_parser_peek_token (parser); |
| 11748 | int idx = 0; |
| 11749 | |
| 11750 | /* Gang static argument. */ |
| 11751 | if (kind == OMP_CLAUSE_GANG |
| 11752 | && c_parser_next_token_is_keyword (parser, RID_STATIC)) |
| 11753 | { |
| 11754 | c_parser_consume_token (parser); |
| 11755 | |
| 11756 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>" )) |
| 11757 | goto cleanup_error; |
| 11758 | |
| 11759 | idx = 1; |
| 11760 | if (ops[idx] != NULL_TREE) |
| 11761 | { |
| 11762 | c_parser_error (parser, "too many %<static%> arguments" ); |
| 11763 | goto cleanup_error; |
| 11764 | } |
| 11765 | |
| 11766 | /* Check for the '*' argument. */ |
| 11767 | if (c_parser_next_token_is (parser, CPP_MULT) |
| 11768 | && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA |
| 11769 | || c_parser_peek_2nd_token (parser)->type |
| 11770 | == CPP_CLOSE_PAREN)) |
| 11771 | { |
| 11772 | c_parser_consume_token (parser); |
| 11773 | ops[idx] = integer_minus_one_node; |
| 11774 | |
| 11775 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 11776 | { |
| 11777 | c_parser_consume_token (parser); |
| 11778 | continue; |
| 11779 | } |
| 11780 | else |
| 11781 | break; |
| 11782 | } |
| 11783 | } |
| 11784 | /* Worker num: argument and vector length: arguments. */ |
| 11785 | else if (c_parser_next_token_is (parser, CPP_NAME) |
| 11786 | && strcmp (id, IDENTIFIER_POINTER (next->value)) == 0 |
| 11787 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 11788 | { |
| 11789 | c_parser_consume_token (parser); /* id */ |
| 11790 | c_parser_consume_token (parser); /* ':' */ |
| 11791 | } |
| 11792 | |
| 11793 | /* Now collect the actual argument. */ |
| 11794 | if (ops[idx] != NULL_TREE) |
| 11795 | { |
| 11796 | c_parser_error (parser, "unexpected argument" ); |
| 11797 | goto cleanup_error; |
| 11798 | } |
| 11799 | |
| 11800 | location_t expr_loc = c_parser_peek_token (parser)->location; |
| 11801 | c_expr cexpr = c_parser_expr_no_commas (parser, NULL); |
| 11802 | cexpr = convert_lvalue_to_rvalue (expr_loc, cexpr, false, true); |
| 11803 | tree expr = cexpr.value; |
| 11804 | if (expr == error_mark_node) |
| 11805 | goto cleanup_error; |
| 11806 | |
| 11807 | expr = c_fully_fold (expr, false, NULL); |
| 11808 | |
| 11809 | /* Attempt to statically determine when the number isn't a |
| 11810 | positive integer. */ |
| 11811 | |
| 11812 | if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))) |
| 11813 | { |
| 11814 | c_parser_error (parser, "expected integer expression" ); |
| 11815 | return list; |
| 11816 | } |
| 11817 | |
| 11818 | tree c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, expr, |
| 11819 | build_int_cst (TREE_TYPE (expr), 0)); |
| 11820 | if (c == boolean_true_node) |
| 11821 | { |
| 11822 | warning_at (loc, 0, |
| 11823 | "%qs value must be positive" , str); |
| 11824 | expr = integer_one_node; |
| 11825 | } |
| 11826 | |
| 11827 | ops[idx] = expr; |
| 11828 | |
| 11829 | if (kind == OMP_CLAUSE_GANG |
| 11830 | && c_parser_next_token_is (parser, CPP_COMMA)) |
| 11831 | { |
| 11832 | c_parser_consume_token (parser); |
| 11833 | continue; |
| 11834 | } |
| 11835 | break; |
| 11836 | } |
| 11837 | while (1); |
| 11838 | |
| 11839 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>" )) |
| 11840 | goto cleanup_error; |
| 11841 | } |
| 11842 | |
| 11843 | check_no_duplicate_clause (list, kind, str); |
| 11844 | |
| 11845 | c = build_omp_clause (loc, kind); |
| 11846 | |
| 11847 | if (ops[1]) |
| 11848 | OMP_CLAUSE_OPERAND (c, 1) = ops[1]; |
| 11849 | |
| 11850 | OMP_CLAUSE_OPERAND (c, 0) = ops[0]; |
| 11851 | OMP_CLAUSE_CHAIN (c) = list; |
| 11852 | |
| 11853 | return c; |
| 11854 | |
| 11855 | cleanup_error: |
| 11856 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); |
| 11857 | return list; |
| 11858 | } |
| 11859 | |
| 11860 | /* OpenACC: |
| 11861 | auto |
| 11862 | independent |
| 11863 | nohost |
| 11864 | seq */ |
| 11865 | |
| 11866 | static tree |
| 11867 | c_parser_oacc_simple_clause (c_parser *parser, enum omp_clause_code code, |
| 11868 | tree list) |
| 11869 | { |
| 11870 | check_no_duplicate_clause (list, code, omp_clause_code_name[code]); |
| 11871 | |
| 11872 | tree c = build_omp_clause (c_parser_peek_token (parser)->location, code); |
| 11873 | OMP_CLAUSE_CHAIN (c) = list; |
| 11874 | |
| 11875 | return c; |
| 11876 | } |
| 11877 | |
| 11878 | /* OpenACC: |
| 11879 | async [( int-expr )] */ |
| 11880 | |
| 11881 | static tree |
| 11882 | c_parser_oacc_clause_async (c_parser *parser, tree list) |
| 11883 | { |
| 11884 | tree c, t; |
| 11885 | location_t loc = c_parser_peek_token (parser)->location; |
| 11886 | |
| 11887 | t = build_int_cst (integer_type_node, GOMP_ASYNC_NOVAL); |
| 11888 | |
| 11889 | if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) |
| 11890 | { |
| 11891 | c_parser_consume_token (parser); |
| 11892 | |
| 11893 | t = c_parser_expression (parser).value; |
| 11894 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 11895 | c_parser_error (parser, "expected integer expression" ); |
| 11896 | else if (t == error_mark_node |
| 11897 | || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>" )) |
| 11898 | return list; |
| 11899 | } |
| 11900 | else |
| 11901 | t = c_fully_fold (t, false, NULL); |
| 11902 | |
| 11903 | check_no_duplicate_clause (list, OMP_CLAUSE_ASYNC, "async" ); |
| 11904 | |
| 11905 | c = build_omp_clause (loc, OMP_CLAUSE_ASYNC); |
| 11906 | OMP_CLAUSE_ASYNC_EXPR (c) = t; |
| 11907 | OMP_CLAUSE_CHAIN (c) = list; |
| 11908 | list = c; |
| 11909 | |
| 11910 | return list; |
| 11911 | } |
| 11912 | |
| 11913 | /* OpenACC 2.0: |
| 11914 | tile ( size-expr-list ) */ |
| 11915 | |
| 11916 | static tree |
| 11917 | c_parser_oacc_clause_tile (c_parser *parser, tree list) |
| 11918 | { |
| 11919 | tree c, expr = error_mark_node; |
| 11920 | location_t loc; |
| 11921 | tree tile = NULL_TREE; |
| 11922 | |
| 11923 | check_no_duplicate_clause (list, OMP_CLAUSE_TILE, "tile" ); |
| 11924 | check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse" ); |
| 11925 | |
| 11926 | loc = c_parser_peek_token (parser)->location; |
| 11927 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 11928 | return list; |
| 11929 | |
| 11930 | do |
| 11931 | { |
| 11932 | if (tile && !c_parser_require (parser, CPP_COMMA, "expected %<,%>" )) |
| 11933 | return list; |
| 11934 | |
| 11935 | if (c_parser_next_token_is (parser, CPP_MULT) |
| 11936 | && (c_parser_peek_2nd_token (parser)->type == CPP_COMMA |
| 11937 | || c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN)) |
| 11938 | { |
| 11939 | c_parser_consume_token (parser); |
| 11940 | expr = integer_zero_node; |
| 11941 | } |
| 11942 | else |
| 11943 | { |
| 11944 | location_t expr_loc = c_parser_peek_token (parser)->location; |
| 11945 | c_expr cexpr = c_parser_expr_no_commas (parser, NULL); |
| 11946 | cexpr = convert_lvalue_to_rvalue (expr_loc, cexpr, false, true); |
| 11947 | expr = cexpr.value; |
| 11948 | |
| 11949 | if (expr == error_mark_node) |
| 11950 | { |
| 11951 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 11952 | "expected %<)%>" ); |
| 11953 | return list; |
| 11954 | } |
| 11955 | |
| 11956 | expr = c_fully_fold (expr, false, NULL); |
| 11957 | |
| 11958 | if (!INTEGRAL_TYPE_P (TREE_TYPE (expr)) |
| 11959 | || !tree_fits_shwi_p (expr) |
| 11960 | || tree_to_shwi (expr) <= 0) |
| 11961 | { |
| 11962 | error_at (expr_loc, "%<tile%> argument needs positive" |
| 11963 | " integral constant" ); |
| 11964 | expr = integer_zero_node; |
| 11965 | } |
| 11966 | } |
| 11967 | |
| 11968 | tile = tree_cons (NULL_TREE, expr, tile); |
| 11969 | } |
| 11970 | while (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)); |
| 11971 | |
| 11972 | /* Consume the trailing ')'. */ |
| 11973 | c_parser_consume_token (parser); |
| 11974 | |
| 11975 | c = build_omp_clause (loc, OMP_CLAUSE_TILE); |
| 11976 | tile = nreverse (tile); |
| 11977 | OMP_CLAUSE_TILE_LIST (c) = tile; |
| 11978 | OMP_CLAUSE_CHAIN (c) = list; |
| 11979 | return c; |
| 11980 | } |
| 11981 | |
| 11982 | /* OpenACC: |
| 11983 | wait ( int-expr-list ) */ |
| 11984 | |
| 11985 | static tree |
| 11986 | c_parser_oacc_clause_wait (c_parser *parser, tree list) |
| 11987 | { |
| 11988 | location_t clause_loc = c_parser_peek_token (parser)->location; |
| 11989 | |
| 11990 | if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) |
| 11991 | list = c_parser_oacc_wait_list (parser, clause_loc, list); |
| 11992 | |
| 11993 | return list; |
| 11994 | } |
| 11995 | |
| 11996 | /* OpenMP 2.5: |
| 11997 | ordered |
| 11998 | |
| 11999 | OpenMP 4.5: |
| 12000 | ordered ( constant-expression ) */ |
| 12001 | |
| 12002 | static tree |
| 12003 | c_parser_omp_clause_ordered (c_parser *parser, tree list) |
| 12004 | { |
| 12005 | check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered" ); |
| 12006 | |
| 12007 | tree c, num = NULL_TREE; |
| 12008 | HOST_WIDE_INT n; |
| 12009 | location_t loc = c_parser_peek_token (parser)->location; |
| 12010 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 12011 | { |
| 12012 | c_parser_consume_token (parser); |
| 12013 | num = c_parser_expr_no_commas (parser, NULL).value; |
| 12014 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 12015 | } |
| 12016 | if (num == error_mark_node) |
| 12017 | return list; |
| 12018 | if (num) |
| 12019 | { |
| 12020 | mark_exp_read (num); |
| 12021 | num = c_fully_fold (num, false, NULL); |
| 12022 | if (!INTEGRAL_TYPE_P (TREE_TYPE (num)) |
| 12023 | || !tree_fits_shwi_p (num) |
| 12024 | || (n = tree_to_shwi (num)) <= 0 |
| 12025 | || (int) n != n) |
| 12026 | { |
| 12027 | error_at (loc, "ordered argument needs positive " |
| 12028 | "constant integer expression" ); |
| 12029 | return list; |
| 12030 | } |
| 12031 | } |
| 12032 | c = build_omp_clause (loc, OMP_CLAUSE_ORDERED); |
| 12033 | OMP_CLAUSE_ORDERED_EXPR (c) = num; |
| 12034 | OMP_CLAUSE_CHAIN (c) = list; |
| 12035 | return c; |
| 12036 | } |
| 12037 | |
| 12038 | /* OpenMP 2.5: |
| 12039 | private ( variable-list ) */ |
| 12040 | |
| 12041 | static tree |
| 12042 | c_parser_omp_clause_private (c_parser *parser, tree list) |
| 12043 | { |
| 12044 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list); |
| 12045 | } |
| 12046 | |
| 12047 | /* OpenMP 2.5: |
| 12048 | reduction ( reduction-operator : variable-list ) |
| 12049 | |
| 12050 | reduction-operator: |
| 12051 | One of: + * - & ^ | && || |
| 12052 | |
| 12053 | OpenMP 3.1: |
| 12054 | |
| 12055 | reduction-operator: |
| 12056 | One of: + * - & ^ | && || max min |
| 12057 | |
| 12058 | OpenMP 4.0: |
| 12059 | |
| 12060 | reduction-operator: |
| 12061 | One of: + * - & ^ | && || |
| 12062 | identifier */ |
| 12063 | |
| 12064 | static tree |
| 12065 | c_parser_omp_clause_reduction (c_parser *parser, tree list) |
| 12066 | { |
| 12067 | location_t clause_loc = c_parser_peek_token (parser)->location; |
| 12068 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 12069 | { |
| 12070 | enum tree_code code = ERROR_MARK; |
| 12071 | tree reduc_id = NULL_TREE; |
| 12072 | |
| 12073 | switch (c_parser_peek_token (parser)->type) |
| 12074 | { |
| 12075 | case CPP_PLUS: |
| 12076 | code = PLUS_EXPR; |
| 12077 | break; |
| 12078 | case CPP_MULT: |
| 12079 | code = MULT_EXPR; |
| 12080 | break; |
| 12081 | case CPP_MINUS: |
| 12082 | code = MINUS_EXPR; |
| 12083 | break; |
| 12084 | case CPP_AND: |
| 12085 | code = BIT_AND_EXPR; |
| 12086 | break; |
| 12087 | case CPP_XOR: |
| 12088 | code = BIT_XOR_EXPR; |
| 12089 | break; |
| 12090 | case CPP_OR: |
| 12091 | code = BIT_IOR_EXPR; |
| 12092 | break; |
| 12093 | case CPP_AND_AND: |
| 12094 | code = TRUTH_ANDIF_EXPR; |
| 12095 | break; |
| 12096 | case CPP_OR_OR: |
| 12097 | code = TRUTH_ORIF_EXPR; |
| 12098 | break; |
| 12099 | case CPP_NAME: |
| 12100 | { |
| 12101 | const char *p |
| 12102 | = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 12103 | if (strcmp (p, "min" ) == 0) |
| 12104 | { |
| 12105 | code = MIN_EXPR; |
| 12106 | break; |
| 12107 | } |
| 12108 | if (strcmp (p, "max" ) == 0) |
| 12109 | { |
| 12110 | code = MAX_EXPR; |
| 12111 | break; |
| 12112 | } |
| 12113 | reduc_id = c_parser_peek_token (parser)->value; |
| 12114 | break; |
| 12115 | } |
| 12116 | default: |
| 12117 | c_parser_error (parser, |
| 12118 | "expected %<+%>, %<*%>, %<-%>, %<&%>, " |
| 12119 | "%<^%>, %<|%>, %<&&%>, %<||%> or identifier" ); |
| 12120 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); |
| 12121 | return list; |
| 12122 | } |
| 12123 | c_parser_consume_token (parser); |
| 12124 | reduc_id = c_omp_reduction_id (code, reduc_id); |
| 12125 | if (c_parser_require (parser, CPP_COLON, "expected %<:%>" )) |
| 12126 | { |
| 12127 | tree nl, c; |
| 12128 | |
| 12129 | nl = c_parser_omp_variable_list (parser, clause_loc, |
| 12130 | OMP_CLAUSE_REDUCTION, list); |
| 12131 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
| 12132 | { |
| 12133 | tree d = OMP_CLAUSE_DECL (c), type; |
| 12134 | if (TREE_CODE (d) != TREE_LIST) |
| 12135 | type = TREE_TYPE (d); |
| 12136 | else |
| 12137 | { |
| 12138 | int cnt = 0; |
| 12139 | tree t; |
| 12140 | for (t = d; TREE_CODE (t) == TREE_LIST; t = TREE_CHAIN (t)) |
| 12141 | cnt++; |
| 12142 | type = TREE_TYPE (t); |
| 12143 | while (cnt > 0) |
| 12144 | { |
| 12145 | if (TREE_CODE (type) != POINTER_TYPE |
| 12146 | && TREE_CODE (type) != ARRAY_TYPE) |
| 12147 | break; |
| 12148 | type = TREE_TYPE (type); |
| 12149 | cnt--; |
| 12150 | } |
| 12151 | } |
| 12152 | while (TREE_CODE (type) == ARRAY_TYPE) |
| 12153 | type = TREE_TYPE (type); |
| 12154 | OMP_CLAUSE_REDUCTION_CODE (c) = code; |
| 12155 | if (code == ERROR_MARK |
| 12156 | || !(INTEGRAL_TYPE_P (type) |
| 12157 | || TREE_CODE (type) == REAL_TYPE |
| 12158 | || TREE_CODE (type) == COMPLEX_TYPE)) |
| 12159 | OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) |
| 12160 | = c_omp_reduction_lookup (reduc_id, |
| 12161 | TYPE_MAIN_VARIANT (type)); |
| 12162 | } |
| 12163 | |
| 12164 | list = nl; |
| 12165 | } |
| 12166 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 12167 | } |
| 12168 | return list; |
| 12169 | } |
| 12170 | |
| 12171 | /* OpenMP 2.5: |
| 12172 | schedule ( schedule-kind ) |
| 12173 | schedule ( schedule-kind , expression ) |
| 12174 | |
| 12175 | schedule-kind: |
| 12176 | static | dynamic | guided | runtime | auto |
| 12177 | |
| 12178 | OpenMP 4.5: |
| 12179 | schedule ( schedule-modifier : schedule-kind ) |
| 12180 | schedule ( schedule-modifier [ , schedule-modifier ] : schedule-kind , expression ) |
| 12181 | |
| 12182 | schedule-modifier: |
| 12183 | simd |
| 12184 | monotonic |
| 12185 | nonmonotonic */ |
| 12186 | |
| 12187 | static tree |
| 12188 | c_parser_omp_clause_schedule (c_parser *parser, tree list) |
| 12189 | { |
| 12190 | tree c, t; |
| 12191 | location_t loc = c_parser_peek_token (parser)->location; |
| 12192 | int modifiers = 0, nmodifiers = 0; |
| 12193 | |
| 12194 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 12195 | return list; |
| 12196 | |
| 12197 | c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE); |
| 12198 | |
| 12199 | while (c_parser_next_token_is (parser, CPP_NAME)) |
| 12200 | { |
| 12201 | tree kind = c_parser_peek_token (parser)->value; |
| 12202 | const char *p = IDENTIFIER_POINTER (kind); |
| 12203 | if (strcmp ("simd" , p) == 0) |
| 12204 | OMP_CLAUSE_SCHEDULE_SIMD (c) = 1; |
| 12205 | else if (strcmp ("monotonic" , p) == 0) |
| 12206 | modifiers |= OMP_CLAUSE_SCHEDULE_MONOTONIC; |
| 12207 | else if (strcmp ("nonmonotonic" , p) == 0) |
| 12208 | modifiers |= OMP_CLAUSE_SCHEDULE_NONMONOTONIC; |
| 12209 | else |
| 12210 | break; |
| 12211 | c_parser_consume_token (parser); |
| 12212 | if (nmodifiers++ == 0 |
| 12213 | && c_parser_next_token_is (parser, CPP_COMMA)) |
| 12214 | c_parser_consume_token (parser); |
| 12215 | else |
| 12216 | { |
| 12217 | c_parser_require (parser, CPP_COLON, "expected %<:%>" ); |
| 12218 | break; |
| 12219 | } |
| 12220 | } |
| 12221 | |
| 12222 | if ((modifiers & (OMP_CLAUSE_SCHEDULE_MONOTONIC |
| 12223 | | OMP_CLAUSE_SCHEDULE_NONMONOTONIC)) |
| 12224 | == (OMP_CLAUSE_SCHEDULE_MONOTONIC |
| 12225 | | OMP_CLAUSE_SCHEDULE_NONMONOTONIC)) |
| 12226 | { |
| 12227 | error_at (loc, "both %<monotonic%> and %<nonmonotonic%> modifiers " |
| 12228 | "specified" ); |
| 12229 | modifiers = 0; |
| 12230 | } |
| 12231 | |
| 12232 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 12233 | { |
| 12234 | tree kind = c_parser_peek_token (parser)->value; |
| 12235 | const char *p = IDENTIFIER_POINTER (kind); |
| 12236 | |
| 12237 | switch (p[0]) |
| 12238 | { |
| 12239 | case 'd': |
| 12240 | if (strcmp ("dynamic" , p) != 0) |
| 12241 | goto invalid_kind; |
| 12242 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC; |
| 12243 | break; |
| 12244 | |
| 12245 | case 'g': |
| 12246 | if (strcmp ("guided" , p) != 0) |
| 12247 | goto invalid_kind; |
| 12248 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED; |
| 12249 | break; |
| 12250 | |
| 12251 | case 'r': |
| 12252 | if (strcmp ("runtime" , p) != 0) |
| 12253 | goto invalid_kind; |
| 12254 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME; |
| 12255 | break; |
| 12256 | |
| 12257 | default: |
| 12258 | goto invalid_kind; |
| 12259 | } |
| 12260 | } |
| 12261 | else if (c_parser_next_token_is_keyword (parser, RID_STATIC)) |
| 12262 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC; |
| 12263 | else if (c_parser_next_token_is_keyword (parser, RID_AUTO)) |
| 12264 | OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO; |
| 12265 | else |
| 12266 | goto invalid_kind; |
| 12267 | |
| 12268 | c_parser_consume_token (parser); |
| 12269 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 12270 | { |
| 12271 | location_t here; |
| 12272 | c_parser_consume_token (parser); |
| 12273 | |
| 12274 | here = c_parser_peek_token (parser)->location; |
| 12275 | c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 12276 | expr = convert_lvalue_to_rvalue (here, expr, false, true); |
| 12277 | t = expr.value; |
| 12278 | t = c_fully_fold (t, false, NULL); |
| 12279 | |
| 12280 | if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME) |
| 12281 | error_at (here, "schedule %<runtime%> does not take " |
| 12282 | "a %<chunk_size%> parameter" ); |
| 12283 | else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO) |
| 12284 | error_at (here, |
| 12285 | "schedule %<auto%> does not take " |
| 12286 | "a %<chunk_size%> parameter" ); |
| 12287 | else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE) |
| 12288 | { |
| 12289 | /* Attempt to statically determine when the number isn't |
| 12290 | positive. */ |
| 12291 | tree s = fold_build2_loc (loc, LE_EXPR, boolean_type_node, t, |
| 12292 | build_int_cst (TREE_TYPE (t), 0)); |
| 12293 | protected_set_expr_location (s, loc); |
| 12294 | if (s == boolean_true_node) |
| 12295 | { |
| 12296 | warning_at (loc, 0, |
| 12297 | "chunk size value must be positive" ); |
| 12298 | t = integer_one_node; |
| 12299 | } |
| 12300 | OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t; |
| 12301 | } |
| 12302 | else |
| 12303 | c_parser_error (parser, "expected integer expression" ); |
| 12304 | |
| 12305 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 12306 | } |
| 12307 | else |
| 12308 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 12309 | "expected %<,%> or %<)%>" ); |
| 12310 | |
| 12311 | OMP_CLAUSE_SCHEDULE_KIND (c) |
| 12312 | = (enum omp_clause_schedule_kind) |
| 12313 | (OMP_CLAUSE_SCHEDULE_KIND (c) | modifiers); |
| 12314 | |
| 12315 | check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule" ); |
| 12316 | OMP_CLAUSE_CHAIN (c) = list; |
| 12317 | return c; |
| 12318 | |
| 12319 | invalid_kind: |
| 12320 | c_parser_error (parser, "invalid schedule kind" ); |
| 12321 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); |
| 12322 | return list; |
| 12323 | } |
| 12324 | |
| 12325 | /* OpenMP 2.5: |
| 12326 | shared ( variable-list ) */ |
| 12327 | |
| 12328 | static tree |
| 12329 | c_parser_omp_clause_shared (c_parser *parser, tree list) |
| 12330 | { |
| 12331 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list); |
| 12332 | } |
| 12333 | |
| 12334 | /* OpenMP 3.0: |
| 12335 | untied */ |
| 12336 | |
| 12337 | static tree |
| 12338 | c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list) |
| 12339 | { |
| 12340 | tree c; |
| 12341 | |
| 12342 | /* FIXME: Should we allow duplicates? */ |
| 12343 | check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied" ); |
| 12344 | |
| 12345 | c = build_omp_clause (c_parser_peek_token (parser)->location, |
| 12346 | OMP_CLAUSE_UNTIED); |
| 12347 | OMP_CLAUSE_CHAIN (c) = list; |
| 12348 | |
| 12349 | return c; |
| 12350 | } |
| 12351 | |
| 12352 | /* OpenACC: |
| 12353 | vector_length ( expression ) */ |
| 12354 | |
| 12355 | static tree |
| 12356 | c_parser_omp_clause_vector_length (c_parser *parser, tree list) |
| 12357 | { |
| 12358 | location_t vector_length_loc = c_parser_peek_token (parser)->location; |
| 12359 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 12360 | { |
| 12361 | location_t expr_loc = c_parser_peek_token (parser)->location; |
| 12362 | c_expr expr = c_parser_expression (parser); |
| 12363 | expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 12364 | tree c, t = expr.value; |
| 12365 | t = c_fully_fold (t, false, NULL); |
| 12366 | |
| 12367 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 12368 | |
| 12369 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 12370 | { |
| 12371 | c_parser_error (parser, "expected integer expression" ); |
| 12372 | return list; |
| 12373 | } |
| 12374 | |
| 12375 | /* Attempt to statically determine when the number isn't positive. */ |
| 12376 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, |
| 12377 | build_int_cst (TREE_TYPE (t), 0)); |
| 12378 | protected_set_expr_location (c, expr_loc); |
| 12379 | if (c == boolean_true_node) |
| 12380 | { |
| 12381 | warning_at (expr_loc, 0, |
| 12382 | "%<vector_length%> value must be positive" ); |
| 12383 | t = integer_one_node; |
| 12384 | } |
| 12385 | |
| 12386 | check_no_duplicate_clause (list, OMP_CLAUSE_VECTOR_LENGTH, "vector_length" ); |
| 12387 | |
| 12388 | c = build_omp_clause (vector_length_loc, OMP_CLAUSE_VECTOR_LENGTH); |
| 12389 | OMP_CLAUSE_VECTOR_LENGTH_EXPR (c) = t; |
| 12390 | OMP_CLAUSE_CHAIN (c) = list; |
| 12391 | list = c; |
| 12392 | } |
| 12393 | |
| 12394 | return list; |
| 12395 | } |
| 12396 | |
| 12397 | /* OpenMP 4.0: |
| 12398 | inbranch |
| 12399 | notinbranch */ |
| 12400 | |
| 12401 | static tree |
| 12402 | c_parser_omp_clause_branch (c_parser *parser ATTRIBUTE_UNUSED, |
| 12403 | enum omp_clause_code code, tree list) |
| 12404 | { |
| 12405 | check_no_duplicate_clause (list, code, omp_clause_code_name[code]); |
| 12406 | |
| 12407 | tree c = build_omp_clause (c_parser_peek_token (parser)->location, code); |
| 12408 | OMP_CLAUSE_CHAIN (c) = list; |
| 12409 | |
| 12410 | return c; |
| 12411 | } |
| 12412 | |
| 12413 | /* OpenMP 4.0: |
| 12414 | parallel |
| 12415 | for |
| 12416 | sections |
| 12417 | taskgroup */ |
| 12418 | |
| 12419 | static tree |
| 12420 | c_parser_omp_clause_cancelkind (c_parser *parser ATTRIBUTE_UNUSED, |
| 12421 | enum omp_clause_code code, tree list) |
| 12422 | { |
| 12423 | tree c = build_omp_clause (c_parser_peek_token (parser)->location, code); |
| 12424 | OMP_CLAUSE_CHAIN (c) = list; |
| 12425 | |
| 12426 | return c; |
| 12427 | } |
| 12428 | |
| 12429 | /* OpenMP 4.5: |
| 12430 | nogroup */ |
| 12431 | |
| 12432 | static tree |
| 12433 | c_parser_omp_clause_nogroup (c_parser *parser ATTRIBUTE_UNUSED, tree list) |
| 12434 | { |
| 12435 | check_no_duplicate_clause (list, OMP_CLAUSE_NOGROUP, "nogroup" ); |
| 12436 | tree c = build_omp_clause (c_parser_peek_token (parser)->location, |
| 12437 | OMP_CLAUSE_NOGROUP); |
| 12438 | OMP_CLAUSE_CHAIN (c) = list; |
| 12439 | return c; |
| 12440 | } |
| 12441 | |
| 12442 | /* OpenMP 4.5: |
| 12443 | simd |
| 12444 | threads */ |
| 12445 | |
| 12446 | static tree |
| 12447 | c_parser_omp_clause_orderedkind (c_parser *parser ATTRIBUTE_UNUSED, |
| 12448 | enum omp_clause_code code, tree list) |
| 12449 | { |
| 12450 | check_no_duplicate_clause (list, code, omp_clause_code_name[code]); |
| 12451 | tree c = build_omp_clause (c_parser_peek_token (parser)->location, code); |
| 12452 | OMP_CLAUSE_CHAIN (c) = list; |
| 12453 | return c; |
| 12454 | } |
| 12455 | |
| 12456 | /* OpenMP 4.0: |
| 12457 | num_teams ( expression ) */ |
| 12458 | |
| 12459 | static tree |
| 12460 | c_parser_omp_clause_num_teams (c_parser *parser, tree list) |
| 12461 | { |
| 12462 | location_t num_teams_loc = c_parser_peek_token (parser)->location; |
| 12463 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 12464 | { |
| 12465 | location_t expr_loc = c_parser_peek_token (parser)->location; |
| 12466 | c_expr expr = c_parser_expression (parser); |
| 12467 | expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 12468 | tree c, t = expr.value; |
| 12469 | t = c_fully_fold (t, false, NULL); |
| 12470 | |
| 12471 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 12472 | |
| 12473 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 12474 | { |
| 12475 | c_parser_error (parser, "expected integer expression" ); |
| 12476 | return list; |
| 12477 | } |
| 12478 | |
| 12479 | /* Attempt to statically determine when the number isn't positive. */ |
| 12480 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, |
| 12481 | build_int_cst (TREE_TYPE (t), 0)); |
| 12482 | protected_set_expr_location (c, expr_loc); |
| 12483 | if (c == boolean_true_node) |
| 12484 | { |
| 12485 | warning_at (expr_loc, 0, "%<num_teams%> value must be positive" ); |
| 12486 | t = integer_one_node; |
| 12487 | } |
| 12488 | |
| 12489 | check_no_duplicate_clause (list, OMP_CLAUSE_NUM_TEAMS, "num_teams" ); |
| 12490 | |
| 12491 | c = build_omp_clause (num_teams_loc, OMP_CLAUSE_NUM_TEAMS); |
| 12492 | OMP_CLAUSE_NUM_TEAMS_EXPR (c) = t; |
| 12493 | OMP_CLAUSE_CHAIN (c) = list; |
| 12494 | list = c; |
| 12495 | } |
| 12496 | |
| 12497 | return list; |
| 12498 | } |
| 12499 | |
| 12500 | /* OpenMP 4.0: |
| 12501 | thread_limit ( expression ) */ |
| 12502 | |
| 12503 | static tree |
| 12504 | c_parser_omp_clause_thread_limit (c_parser *parser, tree list) |
| 12505 | { |
| 12506 | location_t num_thread_limit_loc = c_parser_peek_token (parser)->location; |
| 12507 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 12508 | { |
| 12509 | location_t expr_loc = c_parser_peek_token (parser)->location; |
| 12510 | c_expr expr = c_parser_expression (parser); |
| 12511 | expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 12512 | tree c, t = expr.value; |
| 12513 | t = c_fully_fold (t, false, NULL); |
| 12514 | |
| 12515 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 12516 | |
| 12517 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 12518 | { |
| 12519 | c_parser_error (parser, "expected integer expression" ); |
| 12520 | return list; |
| 12521 | } |
| 12522 | |
| 12523 | /* Attempt to statically determine when the number isn't positive. */ |
| 12524 | c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, |
| 12525 | build_int_cst (TREE_TYPE (t), 0)); |
| 12526 | protected_set_expr_location (c, expr_loc); |
| 12527 | if (c == boolean_true_node) |
| 12528 | { |
| 12529 | warning_at (expr_loc, 0, "%<thread_limit%> value must be positive" ); |
| 12530 | t = integer_one_node; |
| 12531 | } |
| 12532 | |
| 12533 | check_no_duplicate_clause (list, OMP_CLAUSE_THREAD_LIMIT, |
| 12534 | "thread_limit" ); |
| 12535 | |
| 12536 | c = build_omp_clause (num_thread_limit_loc, OMP_CLAUSE_THREAD_LIMIT); |
| 12537 | OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t; |
| 12538 | OMP_CLAUSE_CHAIN (c) = list; |
| 12539 | list = c; |
| 12540 | } |
| 12541 | |
| 12542 | return list; |
| 12543 | } |
| 12544 | |
| 12545 | /* OpenMP 4.0: |
| 12546 | aligned ( variable-list ) |
| 12547 | aligned ( variable-list : constant-expression ) */ |
| 12548 | |
| 12549 | static tree |
| 12550 | c_parser_omp_clause_aligned (c_parser *parser, tree list) |
| 12551 | { |
| 12552 | location_t clause_loc = c_parser_peek_token (parser)->location; |
| 12553 | tree nl, c; |
| 12554 | |
| 12555 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 12556 | return list; |
| 12557 | |
| 12558 | nl = c_parser_omp_variable_list (parser, clause_loc, |
| 12559 | OMP_CLAUSE_ALIGNED, list); |
| 12560 | |
| 12561 | if (c_parser_next_token_is (parser, CPP_COLON)) |
| 12562 | { |
| 12563 | c_parser_consume_token (parser); |
| 12564 | location_t expr_loc = c_parser_peek_token (parser)->location; |
| 12565 | c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 12566 | expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 12567 | tree alignment = expr.value; |
| 12568 | alignment = c_fully_fold (alignment, false, NULL); |
| 12569 | if (TREE_CODE (alignment) != INTEGER_CST |
| 12570 | || !INTEGRAL_TYPE_P (TREE_TYPE (alignment)) |
| 12571 | || tree_int_cst_sgn (alignment) != 1) |
| 12572 | { |
| 12573 | error_at (clause_loc, "%<aligned%> clause alignment expression must " |
| 12574 | "be positive constant integer expression" ); |
| 12575 | alignment = NULL_TREE; |
| 12576 | } |
| 12577 | |
| 12578 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
| 12579 | OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = alignment; |
| 12580 | } |
| 12581 | |
| 12582 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 12583 | return nl; |
| 12584 | } |
| 12585 | |
| 12586 | /* OpenMP 4.0: |
| 12587 | linear ( variable-list ) |
| 12588 | linear ( variable-list : expression ) |
| 12589 | |
| 12590 | OpenMP 4.5: |
| 12591 | linear ( modifier ( variable-list ) ) |
| 12592 | linear ( modifier ( variable-list ) : expression ) */ |
| 12593 | |
| 12594 | static tree |
| 12595 | c_parser_omp_clause_linear (c_parser *parser, tree list, bool is_cilk_simd_fn) |
| 12596 | { |
| 12597 | location_t clause_loc = c_parser_peek_token (parser)->location; |
| 12598 | tree nl, c, step; |
| 12599 | enum omp_clause_linear_kind kind = OMP_CLAUSE_LINEAR_DEFAULT; |
| 12600 | |
| 12601 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 12602 | return list; |
| 12603 | |
| 12604 | if (!is_cilk_simd_fn |
| 12605 | && c_parser_next_token_is (parser, CPP_NAME)) |
| 12606 | { |
| 12607 | c_token *tok = c_parser_peek_token (parser); |
| 12608 | const char *p = IDENTIFIER_POINTER (tok->value); |
| 12609 | if (strcmp ("val" , p) == 0) |
| 12610 | kind = OMP_CLAUSE_LINEAR_VAL; |
| 12611 | if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN) |
| 12612 | kind = OMP_CLAUSE_LINEAR_DEFAULT; |
| 12613 | if (kind != OMP_CLAUSE_LINEAR_DEFAULT) |
| 12614 | { |
| 12615 | c_parser_consume_token (parser); |
| 12616 | c_parser_consume_token (parser); |
| 12617 | } |
| 12618 | } |
| 12619 | |
| 12620 | nl = c_parser_omp_variable_list (parser, clause_loc, |
| 12621 | OMP_CLAUSE_LINEAR, list); |
| 12622 | |
| 12623 | if (kind != OMP_CLAUSE_LINEAR_DEFAULT) |
| 12624 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 12625 | |
| 12626 | if (c_parser_next_token_is (parser, CPP_COLON)) |
| 12627 | { |
| 12628 | c_parser_consume_token (parser); |
| 12629 | location_t expr_loc = c_parser_peek_token (parser)->location; |
| 12630 | c_expr expr = c_parser_expression (parser); |
| 12631 | expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 12632 | step = expr.value; |
| 12633 | step = c_fully_fold (step, false, NULL); |
| 12634 | if (is_cilk_simd_fn && TREE_CODE (step) == PARM_DECL) |
| 12635 | { |
| 12636 | sorry ("using parameters for %<linear%> step is not supported yet" ); |
| 12637 | step = integer_one_node; |
| 12638 | } |
| 12639 | if (!INTEGRAL_TYPE_P (TREE_TYPE (step))) |
| 12640 | { |
| 12641 | error_at (clause_loc, "%<linear%> clause step expression must " |
| 12642 | "be integral" ); |
| 12643 | step = integer_one_node; |
| 12644 | } |
| 12645 | |
| 12646 | } |
| 12647 | else |
| 12648 | step = integer_one_node; |
| 12649 | |
| 12650 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
| 12651 | { |
| 12652 | OMP_CLAUSE_LINEAR_STEP (c) = step; |
| 12653 | OMP_CLAUSE_LINEAR_KIND (c) = kind; |
| 12654 | } |
| 12655 | |
| 12656 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 12657 | return nl; |
| 12658 | } |
| 12659 | |
| 12660 | /* OpenMP 4.0: |
| 12661 | safelen ( constant-expression ) */ |
| 12662 | |
| 12663 | static tree |
| 12664 | c_parser_omp_clause_safelen (c_parser *parser, tree list) |
| 12665 | { |
| 12666 | location_t clause_loc = c_parser_peek_token (parser)->location; |
| 12667 | tree c, t; |
| 12668 | |
| 12669 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 12670 | return list; |
| 12671 | |
| 12672 | location_t expr_loc = c_parser_peek_token (parser)->location; |
| 12673 | c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 12674 | expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 12675 | t = expr.value; |
| 12676 | t = c_fully_fold (t, false, NULL); |
| 12677 | if (TREE_CODE (t) != INTEGER_CST |
| 12678 | || !INTEGRAL_TYPE_P (TREE_TYPE (t)) |
| 12679 | || tree_int_cst_sgn (t) != 1) |
| 12680 | { |
| 12681 | error_at (clause_loc, "%<safelen%> clause expression must " |
| 12682 | "be positive constant integer expression" ); |
| 12683 | t = NULL_TREE; |
| 12684 | } |
| 12685 | |
| 12686 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 12687 | if (t == NULL_TREE || t == error_mark_node) |
| 12688 | return list; |
| 12689 | |
| 12690 | check_no_duplicate_clause (list, OMP_CLAUSE_SAFELEN, "safelen" ); |
| 12691 | |
| 12692 | c = build_omp_clause (clause_loc, OMP_CLAUSE_SAFELEN); |
| 12693 | OMP_CLAUSE_SAFELEN_EXPR (c) = t; |
| 12694 | OMP_CLAUSE_CHAIN (c) = list; |
| 12695 | return c; |
| 12696 | } |
| 12697 | |
| 12698 | /* OpenMP 4.0: |
| 12699 | simdlen ( constant-expression ) */ |
| 12700 | |
| 12701 | static tree |
| 12702 | c_parser_omp_clause_simdlen (c_parser *parser, tree list) |
| 12703 | { |
| 12704 | location_t clause_loc = c_parser_peek_token (parser)->location; |
| 12705 | tree c, t; |
| 12706 | |
| 12707 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 12708 | return list; |
| 12709 | |
| 12710 | location_t expr_loc = c_parser_peek_token (parser)->location; |
| 12711 | c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 12712 | expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 12713 | t = expr.value; |
| 12714 | t = c_fully_fold (t, false, NULL); |
| 12715 | if (TREE_CODE (t) != INTEGER_CST |
| 12716 | || !INTEGRAL_TYPE_P (TREE_TYPE (t)) |
| 12717 | || tree_int_cst_sgn (t) != 1) |
| 12718 | { |
| 12719 | error_at (clause_loc, "%<simdlen%> clause expression must " |
| 12720 | "be positive constant integer expression" ); |
| 12721 | t = NULL_TREE; |
| 12722 | } |
| 12723 | |
| 12724 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 12725 | if (t == NULL_TREE || t == error_mark_node) |
| 12726 | return list; |
| 12727 | |
| 12728 | check_no_duplicate_clause (list, OMP_CLAUSE_SIMDLEN, "simdlen" ); |
| 12729 | |
| 12730 | c = build_omp_clause (clause_loc, OMP_CLAUSE_SIMDLEN); |
| 12731 | OMP_CLAUSE_SIMDLEN_EXPR (c) = t; |
| 12732 | OMP_CLAUSE_CHAIN (c) = list; |
| 12733 | return c; |
| 12734 | } |
| 12735 | |
| 12736 | /* OpenMP 4.5: |
| 12737 | vec: |
| 12738 | identifier [+/- integer] |
| 12739 | vec , identifier [+/- integer] |
| 12740 | */ |
| 12741 | |
| 12742 | static tree |
| 12743 | c_parser_omp_clause_depend_sink (c_parser *parser, location_t clause_loc, |
| 12744 | tree list) |
| 12745 | { |
| 12746 | tree vec = NULL; |
| 12747 | if (c_parser_next_token_is_not (parser, CPP_NAME) |
| 12748 | || c_parser_peek_token (parser)->id_kind != C_ID_ID) |
| 12749 | { |
| 12750 | c_parser_error (parser, "expected identifier" ); |
| 12751 | return list; |
| 12752 | } |
| 12753 | |
| 12754 | while (c_parser_next_token_is (parser, CPP_NAME) |
| 12755 | && c_parser_peek_token (parser)->id_kind == C_ID_ID) |
| 12756 | { |
| 12757 | tree t = lookup_name (c_parser_peek_token (parser)->value); |
| 12758 | tree addend = NULL; |
| 12759 | |
| 12760 | if (t == NULL_TREE) |
| 12761 | { |
| 12762 | undeclared_variable (c_parser_peek_token (parser)->location, |
| 12763 | c_parser_peek_token (parser)->value); |
| 12764 | t = error_mark_node; |
| 12765 | } |
| 12766 | |
| 12767 | c_parser_consume_token (parser); |
| 12768 | |
| 12769 | bool neg = false; |
| 12770 | if (c_parser_next_token_is (parser, CPP_MINUS)) |
| 12771 | neg = true; |
| 12772 | else if (!c_parser_next_token_is (parser, CPP_PLUS)) |
| 12773 | { |
| 12774 | addend = integer_zero_node; |
| 12775 | neg = false; |
| 12776 | goto add_to_vector; |
| 12777 | } |
| 12778 | c_parser_consume_token (parser); |
| 12779 | |
| 12780 | if (c_parser_next_token_is_not (parser, CPP_NUMBER)) |
| 12781 | { |
| 12782 | c_parser_error (parser, "expected integer" ); |
| 12783 | return list; |
| 12784 | } |
| 12785 | |
| 12786 | addend = c_parser_peek_token (parser)->value; |
| 12787 | if (TREE_CODE (addend) != INTEGER_CST) |
| 12788 | { |
| 12789 | c_parser_error (parser, "expected integer" ); |
| 12790 | return list; |
| 12791 | } |
| 12792 | c_parser_consume_token (parser); |
| 12793 | |
| 12794 | add_to_vector: |
| 12795 | if (t != error_mark_node) |
| 12796 | { |
| 12797 | vec = tree_cons (addend, t, vec); |
| 12798 | if (neg) |
| 12799 | OMP_CLAUSE_DEPEND_SINK_NEGATIVE (vec) = 1; |
| 12800 | } |
| 12801 | |
| 12802 | if (c_parser_next_token_is_not (parser, CPP_COMMA)) |
| 12803 | break; |
| 12804 | |
| 12805 | c_parser_consume_token (parser); |
| 12806 | } |
| 12807 | |
| 12808 | if (vec == NULL_TREE) |
| 12809 | return list; |
| 12810 | |
| 12811 | tree u = build_omp_clause (clause_loc, OMP_CLAUSE_DEPEND); |
| 12812 | OMP_CLAUSE_DEPEND_KIND (u) = OMP_CLAUSE_DEPEND_SINK; |
| 12813 | OMP_CLAUSE_DECL (u) = nreverse (vec); |
| 12814 | OMP_CLAUSE_CHAIN (u) = list; |
| 12815 | return u; |
| 12816 | } |
| 12817 | |
| 12818 | /* OpenMP 4.0: |
| 12819 | depend ( depend-kind: variable-list ) |
| 12820 | |
| 12821 | depend-kind: |
| 12822 | in | out | inout |
| 12823 | |
| 12824 | OpenMP 4.5: |
| 12825 | depend ( source ) |
| 12826 | |
| 12827 | depend ( sink : vec ) */ |
| 12828 | |
| 12829 | static tree |
| 12830 | c_parser_omp_clause_depend (c_parser *parser, tree list) |
| 12831 | { |
| 12832 | location_t clause_loc = c_parser_peek_token (parser)->location; |
| 12833 | enum omp_clause_depend_kind kind = OMP_CLAUSE_DEPEND_INOUT; |
| 12834 | tree nl, c; |
| 12835 | |
| 12836 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 12837 | return list; |
| 12838 | |
| 12839 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 12840 | { |
| 12841 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 12842 | if (strcmp ("in" , p) == 0) |
| 12843 | kind = OMP_CLAUSE_DEPEND_IN; |
| 12844 | else if (strcmp ("inout" , p) == 0) |
| 12845 | kind = OMP_CLAUSE_DEPEND_INOUT; |
| 12846 | else if (strcmp ("out" , p) == 0) |
| 12847 | kind = OMP_CLAUSE_DEPEND_OUT; |
| 12848 | else if (strcmp ("source" , p) == 0) |
| 12849 | kind = OMP_CLAUSE_DEPEND_SOURCE; |
| 12850 | else if (strcmp ("sink" , p) == 0) |
| 12851 | kind = OMP_CLAUSE_DEPEND_SINK; |
| 12852 | else |
| 12853 | goto invalid_kind; |
| 12854 | } |
| 12855 | else |
| 12856 | goto invalid_kind; |
| 12857 | |
| 12858 | c_parser_consume_token (parser); |
| 12859 | |
| 12860 | if (kind == OMP_CLAUSE_DEPEND_SOURCE) |
| 12861 | { |
| 12862 | c = build_omp_clause (clause_loc, OMP_CLAUSE_DEPEND); |
| 12863 | OMP_CLAUSE_DEPEND_KIND (c) = kind; |
| 12864 | OMP_CLAUSE_DECL (c) = NULL_TREE; |
| 12865 | OMP_CLAUSE_CHAIN (c) = list; |
| 12866 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 12867 | return c; |
| 12868 | } |
| 12869 | |
| 12870 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>" )) |
| 12871 | goto resync_fail; |
| 12872 | |
| 12873 | if (kind == OMP_CLAUSE_DEPEND_SINK) |
| 12874 | nl = c_parser_omp_clause_depend_sink (parser, clause_loc, list); |
| 12875 | else |
| 12876 | { |
| 12877 | nl = c_parser_omp_variable_list (parser, clause_loc, |
| 12878 | OMP_CLAUSE_DEPEND, list); |
| 12879 | |
| 12880 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
| 12881 | OMP_CLAUSE_DEPEND_KIND (c) = kind; |
| 12882 | } |
| 12883 | |
| 12884 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 12885 | return nl; |
| 12886 | |
| 12887 | invalid_kind: |
| 12888 | c_parser_error (parser, "invalid depend kind" ); |
| 12889 | resync_fail: |
| 12890 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 12891 | return list; |
| 12892 | } |
| 12893 | |
| 12894 | /* OpenMP 4.0: |
| 12895 | map ( map-kind: variable-list ) |
| 12896 | map ( variable-list ) |
| 12897 | |
| 12898 | map-kind: |
| 12899 | alloc | to | from | tofrom |
| 12900 | |
| 12901 | OpenMP 4.5: |
| 12902 | map-kind: |
| 12903 | alloc | to | from | tofrom | release | delete |
| 12904 | |
| 12905 | map ( always [,] map-kind: variable-list ) */ |
| 12906 | |
| 12907 | static tree |
| 12908 | c_parser_omp_clause_map (c_parser *parser, tree list) |
| 12909 | { |
| 12910 | location_t clause_loc = c_parser_peek_token (parser)->location; |
| 12911 | enum gomp_map_kind kind = GOMP_MAP_TOFROM; |
| 12912 | int always = 0; |
| 12913 | enum c_id_kind always_id_kind = C_ID_NONE; |
| 12914 | location_t always_loc = UNKNOWN_LOCATION; |
| 12915 | tree always_id = NULL_TREE; |
| 12916 | tree nl, c; |
| 12917 | |
| 12918 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 12919 | return list; |
| 12920 | |
| 12921 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 12922 | { |
| 12923 | c_token *tok = c_parser_peek_token (parser); |
| 12924 | const char *p = IDENTIFIER_POINTER (tok->value); |
| 12925 | always_id_kind = tok->id_kind; |
| 12926 | always_loc = tok->location; |
| 12927 | always_id = tok->value; |
| 12928 | if (strcmp ("always" , p) == 0) |
| 12929 | { |
| 12930 | c_token *sectok = c_parser_peek_2nd_token (parser); |
| 12931 | if (sectok->type == CPP_COMMA) |
| 12932 | { |
| 12933 | c_parser_consume_token (parser); |
| 12934 | c_parser_consume_token (parser); |
| 12935 | always = 2; |
| 12936 | } |
| 12937 | else if (sectok->type == CPP_NAME) |
| 12938 | { |
| 12939 | p = IDENTIFIER_POINTER (sectok->value); |
| 12940 | if (strcmp ("alloc" , p) == 0 |
| 12941 | || strcmp ("to" , p) == 0 |
| 12942 | || strcmp ("from" , p) == 0 |
| 12943 | || strcmp ("tofrom" , p) == 0 |
| 12944 | || strcmp ("release" , p) == 0 |
| 12945 | || strcmp ("delete" , p) == 0) |
| 12946 | { |
| 12947 | c_parser_consume_token (parser); |
| 12948 | always = 1; |
| 12949 | } |
| 12950 | } |
| 12951 | } |
| 12952 | } |
| 12953 | |
| 12954 | if (c_parser_next_token_is (parser, CPP_NAME) |
| 12955 | && c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 12956 | { |
| 12957 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 12958 | if (strcmp ("alloc" , p) == 0) |
| 12959 | kind = GOMP_MAP_ALLOC; |
| 12960 | else if (strcmp ("to" , p) == 0) |
| 12961 | kind = always ? GOMP_MAP_ALWAYS_TO : GOMP_MAP_TO; |
| 12962 | else if (strcmp ("from" , p) == 0) |
| 12963 | kind = always ? GOMP_MAP_ALWAYS_FROM : GOMP_MAP_FROM; |
| 12964 | else if (strcmp ("tofrom" , p) == 0) |
| 12965 | kind = always ? GOMP_MAP_ALWAYS_TOFROM : GOMP_MAP_TOFROM; |
| 12966 | else if (strcmp ("release" , p) == 0) |
| 12967 | kind = GOMP_MAP_RELEASE; |
| 12968 | else if (strcmp ("delete" , p) == 0) |
| 12969 | kind = GOMP_MAP_DELETE; |
| 12970 | else |
| 12971 | { |
| 12972 | c_parser_error (parser, "invalid map kind" ); |
| 12973 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 12974 | "expected %<)%>" ); |
| 12975 | return list; |
| 12976 | } |
| 12977 | c_parser_consume_token (parser); |
| 12978 | c_parser_consume_token (parser); |
| 12979 | } |
| 12980 | else if (always) |
| 12981 | { |
| 12982 | if (always_id_kind != C_ID_ID) |
| 12983 | { |
| 12984 | c_parser_error (parser, "expected identifier" ); |
| 12985 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 12986 | return list; |
| 12987 | } |
| 12988 | |
| 12989 | tree t = lookup_name (always_id); |
| 12990 | if (t == NULL_TREE) |
| 12991 | { |
| 12992 | undeclared_variable (always_loc, always_id); |
| 12993 | t = error_mark_node; |
| 12994 | } |
| 12995 | if (t != error_mark_node) |
| 12996 | { |
| 12997 | tree u = build_omp_clause (clause_loc, OMP_CLAUSE_MAP); |
| 12998 | OMP_CLAUSE_DECL (u) = t; |
| 12999 | OMP_CLAUSE_CHAIN (u) = list; |
| 13000 | OMP_CLAUSE_SET_MAP_KIND (u, kind); |
| 13001 | list = u; |
| 13002 | } |
| 13003 | if (always == 1) |
| 13004 | { |
| 13005 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 13006 | return list; |
| 13007 | } |
| 13008 | } |
| 13009 | |
| 13010 | nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_MAP, list); |
| 13011 | |
| 13012 | for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) |
| 13013 | OMP_CLAUSE_SET_MAP_KIND (c, kind); |
| 13014 | |
| 13015 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 13016 | return nl; |
| 13017 | } |
| 13018 | |
| 13019 | /* OpenMP 4.0: |
| 13020 | device ( expression ) */ |
| 13021 | |
| 13022 | static tree |
| 13023 | c_parser_omp_clause_device (c_parser *parser, tree list) |
| 13024 | { |
| 13025 | location_t clause_loc = c_parser_peek_token (parser)->location; |
| 13026 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 13027 | { |
| 13028 | location_t expr_loc = c_parser_peek_token (parser)->location; |
| 13029 | c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 13030 | expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 13031 | tree c, t = expr.value; |
| 13032 | t = c_fully_fold (t, false, NULL); |
| 13033 | |
| 13034 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 13035 | |
| 13036 | if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) |
| 13037 | { |
| 13038 | c_parser_error (parser, "expected integer expression" ); |
| 13039 | return list; |
| 13040 | } |
| 13041 | |
| 13042 | check_no_duplicate_clause (list, OMP_CLAUSE_DEVICE, "device" ); |
| 13043 | |
| 13044 | c = build_omp_clause (clause_loc, OMP_CLAUSE_DEVICE); |
| 13045 | OMP_CLAUSE_DEVICE_ID (c) = t; |
| 13046 | OMP_CLAUSE_CHAIN (c) = list; |
| 13047 | list = c; |
| 13048 | } |
| 13049 | |
| 13050 | return list; |
| 13051 | } |
| 13052 | |
| 13053 | /* OpenMP 4.0: |
| 13054 | dist_schedule ( static ) |
| 13055 | dist_schedule ( static , expression ) */ |
| 13056 | |
| 13057 | static tree |
| 13058 | c_parser_omp_clause_dist_schedule (c_parser *parser, tree list) |
| 13059 | { |
| 13060 | tree c, t = NULL_TREE; |
| 13061 | location_t loc = c_parser_peek_token (parser)->location; |
| 13062 | |
| 13063 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 13064 | return list; |
| 13065 | |
| 13066 | if (!c_parser_next_token_is_keyword (parser, RID_STATIC)) |
| 13067 | { |
| 13068 | c_parser_error (parser, "invalid dist_schedule kind" ); |
| 13069 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 13070 | "expected %<)%>" ); |
| 13071 | return list; |
| 13072 | } |
| 13073 | |
| 13074 | c_parser_consume_token (parser); |
| 13075 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 13076 | { |
| 13077 | c_parser_consume_token (parser); |
| 13078 | |
| 13079 | location_t expr_loc = c_parser_peek_token (parser)->location; |
| 13080 | c_expr expr = c_parser_expr_no_commas (parser, NULL); |
| 13081 | expr = convert_lvalue_to_rvalue (expr_loc, expr, false, true); |
| 13082 | t = expr.value; |
| 13083 | t = c_fully_fold (t, false, NULL); |
| 13084 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 13085 | } |
| 13086 | else |
| 13087 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 13088 | "expected %<,%> or %<)%>" ); |
| 13089 | |
| 13090 | check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule" ); |
| 13091 | if (t == error_mark_node) |
| 13092 | return list; |
| 13093 | |
| 13094 | c = build_omp_clause (loc, OMP_CLAUSE_DIST_SCHEDULE); |
| 13095 | OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t; |
| 13096 | OMP_CLAUSE_CHAIN (c) = list; |
| 13097 | return c; |
| 13098 | } |
| 13099 | |
| 13100 | /* OpenMP 4.0: |
| 13101 | proc_bind ( proc-bind-kind ) |
| 13102 | |
| 13103 | proc-bind-kind: |
| 13104 | master | close | spread */ |
| 13105 | |
| 13106 | static tree |
| 13107 | c_parser_omp_clause_proc_bind (c_parser *parser, tree list) |
| 13108 | { |
| 13109 | location_t clause_loc = c_parser_peek_token (parser)->location; |
| 13110 | enum omp_clause_proc_bind_kind kind; |
| 13111 | tree c; |
| 13112 | |
| 13113 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 13114 | return list; |
| 13115 | |
| 13116 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 13117 | { |
| 13118 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 13119 | if (strcmp ("master" , p) == 0) |
| 13120 | kind = OMP_CLAUSE_PROC_BIND_MASTER; |
| 13121 | else if (strcmp ("close" , p) == 0) |
| 13122 | kind = OMP_CLAUSE_PROC_BIND_CLOSE; |
| 13123 | else if (strcmp ("spread" , p) == 0) |
| 13124 | kind = OMP_CLAUSE_PROC_BIND_SPREAD; |
| 13125 | else |
| 13126 | goto invalid_kind; |
| 13127 | } |
| 13128 | else |
| 13129 | goto invalid_kind; |
| 13130 | |
| 13131 | c_parser_consume_token (parser); |
| 13132 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 13133 | c = build_omp_clause (clause_loc, OMP_CLAUSE_PROC_BIND); |
| 13134 | OMP_CLAUSE_PROC_BIND_KIND (c) = kind; |
| 13135 | OMP_CLAUSE_CHAIN (c) = list; |
| 13136 | return c; |
| 13137 | |
| 13138 | invalid_kind: |
| 13139 | c_parser_error (parser, "invalid proc_bind kind" ); |
| 13140 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 13141 | return list; |
| 13142 | } |
| 13143 | |
| 13144 | /* OpenMP 4.0: |
| 13145 | to ( variable-list ) */ |
| 13146 | |
| 13147 | static tree |
| 13148 | c_parser_omp_clause_to (c_parser *parser, tree list) |
| 13149 | { |
| 13150 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO, list); |
| 13151 | } |
| 13152 | |
| 13153 | /* OpenMP 4.0: |
| 13154 | from ( variable-list ) */ |
| 13155 | |
| 13156 | static tree |
| 13157 | c_parser_omp_clause_from (c_parser *parser, tree list) |
| 13158 | { |
| 13159 | return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FROM, list); |
| 13160 | } |
| 13161 | |
| 13162 | /* OpenMP 4.0: |
| 13163 | uniform ( variable-list ) */ |
| 13164 | |
| 13165 | static tree |
| 13166 | c_parser_omp_clause_uniform (c_parser *parser, tree list) |
| 13167 | { |
| 13168 | /* The clauses location. */ |
| 13169 | location_t loc = c_parser_peek_token (parser)->location; |
| 13170 | |
| 13171 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 13172 | { |
| 13173 | list = c_parser_omp_variable_list (parser, loc, OMP_CLAUSE_UNIFORM, |
| 13174 | list); |
| 13175 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 13176 | } |
| 13177 | return list; |
| 13178 | } |
| 13179 | |
| 13180 | /* Parse all OpenACC clauses. The set clauses allowed by the directive |
| 13181 | is a bitmask in MASK. Return the list of clauses found. */ |
| 13182 | |
| 13183 | static tree |
| 13184 | c_parser_oacc_all_clauses (c_parser *parser, omp_clause_mask mask, |
| 13185 | const char *where, bool finish_p = true) |
| 13186 | { |
| 13187 | tree clauses = NULL; |
| 13188 | bool first = true; |
| 13189 | |
| 13190 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
| 13191 | { |
| 13192 | location_t here; |
| 13193 | pragma_omp_clause c_kind; |
| 13194 | const char *c_name; |
| 13195 | tree prev = clauses; |
| 13196 | |
| 13197 | if (!first && c_parser_next_token_is (parser, CPP_COMMA)) |
| 13198 | c_parser_consume_token (parser); |
| 13199 | |
| 13200 | here = c_parser_peek_token (parser)->location; |
| 13201 | c_kind = c_parser_omp_clause_name (parser); |
| 13202 | |
| 13203 | switch (c_kind) |
| 13204 | { |
| 13205 | case PRAGMA_OACC_CLAUSE_ASYNC: |
| 13206 | clauses = c_parser_oacc_clause_async (parser, clauses); |
| 13207 | c_name = "async" ; |
| 13208 | break; |
| 13209 | case PRAGMA_OACC_CLAUSE_AUTO: |
| 13210 | clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_AUTO, |
| 13211 | clauses); |
| 13212 | c_name = "auto" ; |
| 13213 | break; |
| 13214 | case PRAGMA_OACC_CLAUSE_COLLAPSE: |
| 13215 | clauses = c_parser_omp_clause_collapse (parser, clauses); |
| 13216 | c_name = "collapse" ; |
| 13217 | break; |
| 13218 | case PRAGMA_OACC_CLAUSE_COPY: |
| 13219 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 13220 | c_name = "copy" ; |
| 13221 | break; |
| 13222 | case PRAGMA_OACC_CLAUSE_COPYIN: |
| 13223 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 13224 | c_name = "copyin" ; |
| 13225 | break; |
| 13226 | case PRAGMA_OACC_CLAUSE_COPYOUT: |
| 13227 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 13228 | c_name = "copyout" ; |
| 13229 | break; |
| 13230 | case PRAGMA_OACC_CLAUSE_CREATE: |
| 13231 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 13232 | c_name = "create" ; |
| 13233 | break; |
| 13234 | case PRAGMA_OACC_CLAUSE_DELETE: |
| 13235 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 13236 | c_name = "delete" ; |
| 13237 | break; |
| 13238 | case PRAGMA_OMP_CLAUSE_DEFAULT: |
| 13239 | clauses = c_parser_omp_clause_default (parser, clauses, true); |
| 13240 | c_name = "default" ; |
| 13241 | break; |
| 13242 | case PRAGMA_OACC_CLAUSE_DEVICE: |
| 13243 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 13244 | c_name = "device" ; |
| 13245 | break; |
| 13246 | case PRAGMA_OACC_CLAUSE_DEVICEPTR: |
| 13247 | clauses = c_parser_oacc_data_clause_deviceptr (parser, clauses); |
| 13248 | c_name = "deviceptr" ; |
| 13249 | break; |
| 13250 | case PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT: |
| 13251 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 13252 | c_name = "device_resident" ; |
| 13253 | break; |
| 13254 | case PRAGMA_OACC_CLAUSE_FIRSTPRIVATE: |
| 13255 | clauses = c_parser_omp_clause_firstprivate (parser, clauses); |
| 13256 | c_name = "firstprivate" ; |
| 13257 | break; |
| 13258 | case PRAGMA_OACC_CLAUSE_GANG: |
| 13259 | c_name = "gang" ; |
| 13260 | clauses = c_parser_oacc_shape_clause (parser, OMP_CLAUSE_GANG, |
| 13261 | c_name, clauses); |
| 13262 | break; |
| 13263 | case PRAGMA_OACC_CLAUSE_HOST: |
| 13264 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 13265 | c_name = "host" ; |
| 13266 | break; |
| 13267 | case PRAGMA_OACC_CLAUSE_IF: |
| 13268 | clauses = c_parser_omp_clause_if (parser, clauses, false); |
| 13269 | c_name = "if" ; |
| 13270 | break; |
| 13271 | case PRAGMA_OACC_CLAUSE_INDEPENDENT: |
| 13272 | clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_INDEPENDENT, |
| 13273 | clauses); |
| 13274 | c_name = "independent" ; |
| 13275 | break; |
| 13276 | case PRAGMA_OACC_CLAUSE_LINK: |
| 13277 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 13278 | c_name = "link" ; |
| 13279 | break; |
| 13280 | case PRAGMA_OACC_CLAUSE_NUM_GANGS: |
| 13281 | clauses = c_parser_omp_clause_num_gangs (parser, clauses); |
| 13282 | c_name = "num_gangs" ; |
| 13283 | break; |
| 13284 | case PRAGMA_OACC_CLAUSE_NUM_WORKERS: |
| 13285 | clauses = c_parser_omp_clause_num_workers (parser, clauses); |
| 13286 | c_name = "num_workers" ; |
| 13287 | break; |
| 13288 | case PRAGMA_OACC_CLAUSE_PRESENT: |
| 13289 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 13290 | c_name = "present" ; |
| 13291 | break; |
| 13292 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY: |
| 13293 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 13294 | c_name = "present_or_copy" ; |
| 13295 | break; |
| 13296 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN: |
| 13297 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 13298 | c_name = "present_or_copyin" ; |
| 13299 | break; |
| 13300 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT: |
| 13301 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 13302 | c_name = "present_or_copyout" ; |
| 13303 | break; |
| 13304 | case PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE: |
| 13305 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 13306 | c_name = "present_or_create" ; |
| 13307 | break; |
| 13308 | case PRAGMA_OACC_CLAUSE_PRIVATE: |
| 13309 | clauses = c_parser_omp_clause_private (parser, clauses); |
| 13310 | c_name = "private" ; |
| 13311 | break; |
| 13312 | case PRAGMA_OACC_CLAUSE_REDUCTION: |
| 13313 | clauses = c_parser_omp_clause_reduction (parser, clauses); |
| 13314 | c_name = "reduction" ; |
| 13315 | break; |
| 13316 | case PRAGMA_OACC_CLAUSE_SELF: |
| 13317 | clauses = c_parser_oacc_data_clause (parser, c_kind, clauses); |
| 13318 | c_name = "self" ; |
| 13319 | break; |
| 13320 | case PRAGMA_OACC_CLAUSE_SEQ: |
| 13321 | clauses = c_parser_oacc_simple_clause (parser, OMP_CLAUSE_SEQ, |
| 13322 | clauses); |
| 13323 | c_name = "seq" ; |
| 13324 | break; |
| 13325 | case PRAGMA_OACC_CLAUSE_TILE: |
| 13326 | clauses = c_parser_oacc_clause_tile (parser, clauses); |
| 13327 | c_name = "tile" ; |
| 13328 | break; |
| 13329 | case PRAGMA_OACC_CLAUSE_USE_DEVICE: |
| 13330 | clauses = c_parser_omp_clause_use_device_ptr (parser, clauses); |
| 13331 | c_name = "use_device" ; |
| 13332 | break; |
| 13333 | case PRAGMA_OACC_CLAUSE_VECTOR: |
| 13334 | c_name = "vector" ; |
| 13335 | clauses = c_parser_oacc_shape_clause (parser, OMP_CLAUSE_VECTOR, |
| 13336 | c_name, clauses); |
| 13337 | break; |
| 13338 | case PRAGMA_OACC_CLAUSE_VECTOR_LENGTH: |
| 13339 | clauses = c_parser_omp_clause_vector_length (parser, clauses); |
| 13340 | c_name = "vector_length" ; |
| 13341 | break; |
| 13342 | case PRAGMA_OACC_CLAUSE_WAIT: |
| 13343 | clauses = c_parser_oacc_clause_wait (parser, clauses); |
| 13344 | c_name = "wait" ; |
| 13345 | break; |
| 13346 | case PRAGMA_OACC_CLAUSE_WORKER: |
| 13347 | c_name = "worker" ; |
| 13348 | clauses = c_parser_oacc_shape_clause (parser, OMP_CLAUSE_WORKER, |
| 13349 | c_name, clauses); |
| 13350 | break; |
| 13351 | default: |
| 13352 | c_parser_error (parser, "expected %<#pragma acc%> clause" ); |
| 13353 | goto saw_error; |
| 13354 | } |
| 13355 | |
| 13356 | first = false; |
| 13357 | |
| 13358 | if (((mask >> c_kind) & 1) == 0) |
| 13359 | { |
| 13360 | /* Remove the invalid clause(s) from the list to avoid |
| 13361 | confusing the rest of the compiler. */ |
| 13362 | clauses = prev; |
| 13363 | error_at (here, "%qs is not valid for %qs" , c_name, where); |
| 13364 | } |
| 13365 | } |
| 13366 | |
| 13367 | saw_error: |
| 13368 | c_parser_skip_to_pragma_eol (parser); |
| 13369 | |
| 13370 | if (finish_p) |
| 13371 | return c_finish_omp_clauses (clauses, C_ORT_ACC); |
| 13372 | |
| 13373 | return clauses; |
| 13374 | } |
| 13375 | |
| 13376 | /* Parse all OpenMP clauses. The set clauses allowed by the directive |
| 13377 | is a bitmask in MASK. Return the list of clauses found. */ |
| 13378 | |
| 13379 | static tree |
| 13380 | c_parser_omp_all_clauses (c_parser *parser, omp_clause_mask mask, |
| 13381 | const char *where, bool finish_p = true) |
| 13382 | { |
| 13383 | tree clauses = NULL; |
| 13384 | bool first = true, cilk_simd_fn = false; |
| 13385 | |
| 13386 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
| 13387 | { |
| 13388 | location_t here; |
| 13389 | pragma_omp_clause c_kind; |
| 13390 | const char *c_name; |
| 13391 | tree prev = clauses; |
| 13392 | |
| 13393 | if (!first && c_parser_next_token_is (parser, CPP_COMMA)) |
| 13394 | c_parser_consume_token (parser); |
| 13395 | |
| 13396 | here = c_parser_peek_token (parser)->location; |
| 13397 | c_kind = c_parser_omp_clause_name (parser); |
| 13398 | |
| 13399 | switch (c_kind) |
| 13400 | { |
| 13401 | case PRAGMA_OMP_CLAUSE_COLLAPSE: |
| 13402 | clauses = c_parser_omp_clause_collapse (parser, clauses); |
| 13403 | c_name = "collapse" ; |
| 13404 | break; |
| 13405 | case PRAGMA_OMP_CLAUSE_COPYIN: |
| 13406 | clauses = c_parser_omp_clause_copyin (parser, clauses); |
| 13407 | c_name = "copyin" ; |
| 13408 | break; |
| 13409 | case PRAGMA_OMP_CLAUSE_COPYPRIVATE: |
| 13410 | clauses = c_parser_omp_clause_copyprivate (parser, clauses); |
| 13411 | c_name = "copyprivate" ; |
| 13412 | break; |
| 13413 | case PRAGMA_OMP_CLAUSE_DEFAULT: |
| 13414 | clauses = c_parser_omp_clause_default (parser, clauses, false); |
| 13415 | c_name = "default" ; |
| 13416 | break; |
| 13417 | case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE: |
| 13418 | clauses = c_parser_omp_clause_firstprivate (parser, clauses); |
| 13419 | c_name = "firstprivate" ; |
| 13420 | break; |
| 13421 | case PRAGMA_OMP_CLAUSE_FINAL: |
| 13422 | clauses = c_parser_omp_clause_final (parser, clauses); |
| 13423 | c_name = "final" ; |
| 13424 | break; |
| 13425 | case PRAGMA_OMP_CLAUSE_GRAINSIZE: |
| 13426 | clauses = c_parser_omp_clause_grainsize (parser, clauses); |
| 13427 | c_name = "grainsize" ; |
| 13428 | break; |
| 13429 | case PRAGMA_OMP_CLAUSE_HINT: |
| 13430 | clauses = c_parser_omp_clause_hint (parser, clauses); |
| 13431 | c_name = "hint" ; |
| 13432 | break; |
| 13433 | case PRAGMA_OMP_CLAUSE_DEFAULTMAP: |
| 13434 | clauses = c_parser_omp_clause_defaultmap (parser, clauses); |
| 13435 | c_name = "defaultmap" ; |
| 13436 | break; |
| 13437 | case PRAGMA_OMP_CLAUSE_IF: |
| 13438 | clauses = c_parser_omp_clause_if (parser, clauses, true); |
| 13439 | c_name = "if" ; |
| 13440 | break; |
| 13441 | case PRAGMA_OMP_CLAUSE_LASTPRIVATE: |
| 13442 | clauses = c_parser_omp_clause_lastprivate (parser, clauses); |
| 13443 | c_name = "lastprivate" ; |
| 13444 | break; |
| 13445 | case PRAGMA_OMP_CLAUSE_MERGEABLE: |
| 13446 | clauses = c_parser_omp_clause_mergeable (parser, clauses); |
| 13447 | c_name = "mergeable" ; |
| 13448 | break; |
| 13449 | case PRAGMA_OMP_CLAUSE_NOWAIT: |
| 13450 | clauses = c_parser_omp_clause_nowait (parser, clauses); |
| 13451 | c_name = "nowait" ; |
| 13452 | break; |
| 13453 | case PRAGMA_OMP_CLAUSE_NUM_TASKS: |
| 13454 | clauses = c_parser_omp_clause_num_tasks (parser, clauses); |
| 13455 | c_name = "num_tasks" ; |
| 13456 | break; |
| 13457 | case PRAGMA_OMP_CLAUSE_NUM_THREADS: |
| 13458 | clauses = c_parser_omp_clause_num_threads (parser, clauses); |
| 13459 | c_name = "num_threads" ; |
| 13460 | break; |
| 13461 | case PRAGMA_OMP_CLAUSE_ORDERED: |
| 13462 | clauses = c_parser_omp_clause_ordered (parser, clauses); |
| 13463 | c_name = "ordered" ; |
| 13464 | break; |
| 13465 | case PRAGMA_OMP_CLAUSE_PRIORITY: |
| 13466 | clauses = c_parser_omp_clause_priority (parser, clauses); |
| 13467 | c_name = "priority" ; |
| 13468 | break; |
| 13469 | case PRAGMA_OMP_CLAUSE_PRIVATE: |
| 13470 | clauses = c_parser_omp_clause_private (parser, clauses); |
| 13471 | c_name = "private" ; |
| 13472 | break; |
| 13473 | case PRAGMA_OMP_CLAUSE_REDUCTION: |
| 13474 | clauses = c_parser_omp_clause_reduction (parser, clauses); |
| 13475 | c_name = "reduction" ; |
| 13476 | break; |
| 13477 | case PRAGMA_OMP_CLAUSE_SCHEDULE: |
| 13478 | clauses = c_parser_omp_clause_schedule (parser, clauses); |
| 13479 | c_name = "schedule" ; |
| 13480 | break; |
| 13481 | case PRAGMA_OMP_CLAUSE_SHARED: |
| 13482 | clauses = c_parser_omp_clause_shared (parser, clauses); |
| 13483 | c_name = "shared" ; |
| 13484 | break; |
| 13485 | case PRAGMA_OMP_CLAUSE_UNTIED: |
| 13486 | clauses = c_parser_omp_clause_untied (parser, clauses); |
| 13487 | c_name = "untied" ; |
| 13488 | break; |
| 13489 | case PRAGMA_OMP_CLAUSE_INBRANCH: |
| 13490 | case PRAGMA_CILK_CLAUSE_MASK: |
| 13491 | clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_INBRANCH, |
| 13492 | clauses); |
| 13493 | c_name = "inbranch" ; |
| 13494 | break; |
| 13495 | case PRAGMA_OMP_CLAUSE_NOTINBRANCH: |
| 13496 | case PRAGMA_CILK_CLAUSE_NOMASK: |
| 13497 | clauses = c_parser_omp_clause_branch (parser, OMP_CLAUSE_NOTINBRANCH, |
| 13498 | clauses); |
| 13499 | c_name = "notinbranch" ; |
| 13500 | break; |
| 13501 | case PRAGMA_OMP_CLAUSE_PARALLEL: |
| 13502 | clauses |
| 13503 | = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_PARALLEL, |
| 13504 | clauses); |
| 13505 | c_name = "parallel" ; |
| 13506 | if (!first) |
| 13507 | { |
| 13508 | clause_not_first: |
| 13509 | error_at (here, "%qs must be the first clause of %qs" , |
| 13510 | c_name, where); |
| 13511 | clauses = prev; |
| 13512 | } |
| 13513 | break; |
| 13514 | case PRAGMA_OMP_CLAUSE_FOR: |
| 13515 | clauses |
| 13516 | = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_FOR, |
| 13517 | clauses); |
| 13518 | c_name = "for" ; |
| 13519 | if (!first) |
| 13520 | goto clause_not_first; |
| 13521 | break; |
| 13522 | case PRAGMA_OMP_CLAUSE_SECTIONS: |
| 13523 | clauses |
| 13524 | = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_SECTIONS, |
| 13525 | clauses); |
| 13526 | c_name = "sections" ; |
| 13527 | if (!first) |
| 13528 | goto clause_not_first; |
| 13529 | break; |
| 13530 | case PRAGMA_OMP_CLAUSE_TASKGROUP: |
| 13531 | clauses |
| 13532 | = c_parser_omp_clause_cancelkind (parser, OMP_CLAUSE_TASKGROUP, |
| 13533 | clauses); |
| 13534 | c_name = "taskgroup" ; |
| 13535 | if (!first) |
| 13536 | goto clause_not_first; |
| 13537 | break; |
| 13538 | case PRAGMA_OMP_CLAUSE_LINK: |
| 13539 | clauses |
| 13540 | = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LINK, clauses); |
| 13541 | c_name = "link" ; |
| 13542 | break; |
| 13543 | case PRAGMA_OMP_CLAUSE_TO: |
| 13544 | if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK)) != 0) |
| 13545 | clauses |
| 13546 | = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO_DECLARE, |
| 13547 | clauses); |
| 13548 | else |
| 13549 | clauses = c_parser_omp_clause_to (parser, clauses); |
| 13550 | c_name = "to" ; |
| 13551 | break; |
| 13552 | case PRAGMA_OMP_CLAUSE_FROM: |
| 13553 | clauses = c_parser_omp_clause_from (parser, clauses); |
| 13554 | c_name = "from" ; |
| 13555 | break; |
| 13556 | case PRAGMA_OMP_CLAUSE_UNIFORM: |
| 13557 | clauses = c_parser_omp_clause_uniform (parser, clauses); |
| 13558 | c_name = "uniform" ; |
| 13559 | break; |
| 13560 | case PRAGMA_OMP_CLAUSE_NUM_TEAMS: |
| 13561 | clauses = c_parser_omp_clause_num_teams (parser, clauses); |
| 13562 | c_name = "num_teams" ; |
| 13563 | break; |
| 13564 | case PRAGMA_OMP_CLAUSE_THREAD_LIMIT: |
| 13565 | clauses = c_parser_omp_clause_thread_limit (parser, clauses); |
| 13566 | c_name = "thread_limit" ; |
| 13567 | break; |
| 13568 | case PRAGMA_OMP_CLAUSE_ALIGNED: |
| 13569 | clauses = c_parser_omp_clause_aligned (parser, clauses); |
| 13570 | c_name = "aligned" ; |
| 13571 | break; |
| 13572 | case PRAGMA_OMP_CLAUSE_LINEAR: |
| 13573 | if (((mask >> PRAGMA_CILK_CLAUSE_VECTORLENGTH) & 1) != 0) |
| 13574 | cilk_simd_fn = true; |
| 13575 | clauses = c_parser_omp_clause_linear (parser, clauses, cilk_simd_fn); |
| 13576 | c_name = "linear" ; |
| 13577 | break; |
| 13578 | case PRAGMA_OMP_CLAUSE_DEPEND: |
| 13579 | clauses = c_parser_omp_clause_depend (parser, clauses); |
| 13580 | c_name = "depend" ; |
| 13581 | break; |
| 13582 | case PRAGMA_OMP_CLAUSE_MAP: |
| 13583 | clauses = c_parser_omp_clause_map (parser, clauses); |
| 13584 | c_name = "map" ; |
| 13585 | break; |
| 13586 | case PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR: |
| 13587 | clauses = c_parser_omp_clause_use_device_ptr (parser, clauses); |
| 13588 | c_name = "use_device_ptr" ; |
| 13589 | break; |
| 13590 | case PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR: |
| 13591 | clauses = c_parser_omp_clause_is_device_ptr (parser, clauses); |
| 13592 | c_name = "is_device_ptr" ; |
| 13593 | break; |
| 13594 | case PRAGMA_OMP_CLAUSE_DEVICE: |
| 13595 | clauses = c_parser_omp_clause_device (parser, clauses); |
| 13596 | c_name = "device" ; |
| 13597 | break; |
| 13598 | case PRAGMA_OMP_CLAUSE_DIST_SCHEDULE: |
| 13599 | clauses = c_parser_omp_clause_dist_schedule (parser, clauses); |
| 13600 | c_name = "dist_schedule" ; |
| 13601 | break; |
| 13602 | case PRAGMA_OMP_CLAUSE_PROC_BIND: |
| 13603 | clauses = c_parser_omp_clause_proc_bind (parser, clauses); |
| 13604 | c_name = "proc_bind" ; |
| 13605 | break; |
| 13606 | case PRAGMA_OMP_CLAUSE_SAFELEN: |
| 13607 | clauses = c_parser_omp_clause_safelen (parser, clauses); |
| 13608 | c_name = "safelen" ; |
| 13609 | break; |
| 13610 | case PRAGMA_CILK_CLAUSE_VECTORLENGTH: |
| 13611 | clauses = c_parser_cilk_clause_vectorlength (parser, clauses, true); |
| 13612 | c_name = "simdlen" ; |
| 13613 | break; |
| 13614 | case PRAGMA_OMP_CLAUSE_SIMDLEN: |
| 13615 | clauses = c_parser_omp_clause_simdlen (parser, clauses); |
| 13616 | c_name = "simdlen" ; |
| 13617 | break; |
| 13618 | case PRAGMA_OMP_CLAUSE_NOGROUP: |
| 13619 | clauses = c_parser_omp_clause_nogroup (parser, clauses); |
| 13620 | c_name = "nogroup" ; |
| 13621 | break; |
| 13622 | case PRAGMA_OMP_CLAUSE_THREADS: |
| 13623 | clauses |
| 13624 | = c_parser_omp_clause_orderedkind (parser, OMP_CLAUSE_THREADS, |
| 13625 | clauses); |
| 13626 | c_name = "threads" ; |
| 13627 | break; |
| 13628 | case PRAGMA_OMP_CLAUSE_SIMD: |
| 13629 | clauses |
| 13630 | = c_parser_omp_clause_orderedkind (parser, OMP_CLAUSE_SIMD, |
| 13631 | clauses); |
| 13632 | c_name = "simd" ; |
| 13633 | break; |
| 13634 | default: |
| 13635 | c_parser_error (parser, "expected %<#pragma omp%> clause" ); |
| 13636 | goto saw_error; |
| 13637 | } |
| 13638 | |
| 13639 | first = false; |
| 13640 | |
| 13641 | if (((mask >> c_kind) & 1) == 0) |
| 13642 | { |
| 13643 | /* Remove the invalid clause(s) from the list to avoid |
| 13644 | confusing the rest of the compiler. */ |
| 13645 | clauses = prev; |
| 13646 | error_at (here, "%qs is not valid for %qs" , c_name, where); |
| 13647 | } |
| 13648 | } |
| 13649 | |
| 13650 | saw_error: |
| 13651 | c_parser_skip_to_pragma_eol (parser); |
| 13652 | |
| 13653 | if (finish_p) |
| 13654 | { |
| 13655 | if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM)) != 0) |
| 13656 | return c_finish_omp_clauses (clauses, C_ORT_OMP_DECLARE_SIMD); |
| 13657 | return c_finish_omp_clauses (clauses, C_ORT_OMP); |
| 13658 | } |
| 13659 | |
| 13660 | return clauses; |
| 13661 | } |
| 13662 | |
| 13663 | /* OpenACC 2.0, OpenMP 2.5: |
| 13664 | structured-block: |
| 13665 | statement |
| 13666 | |
| 13667 | In practice, we're also interested in adding the statement to an |
| 13668 | outer node. So it is convenient if we work around the fact that |
| 13669 | c_parser_statement calls add_stmt. */ |
| 13670 | |
| 13671 | static tree |
| 13672 | c_parser_omp_structured_block (c_parser *parser, bool *if_p) |
| 13673 | { |
| 13674 | tree stmt = push_stmt_list (); |
| 13675 | c_parser_statement (parser, if_p); |
| 13676 | return pop_stmt_list (stmt); |
| 13677 | } |
| 13678 | |
| 13679 | /* OpenACC 2.0: |
| 13680 | # pragma acc cache (variable-list) new-line |
| 13681 | |
| 13682 | LOC is the location of the #pragma token. |
| 13683 | */ |
| 13684 | |
| 13685 | static tree |
| 13686 | c_parser_oacc_cache (location_t loc, c_parser *parser) |
| 13687 | { |
| 13688 | tree stmt, clauses; |
| 13689 | |
| 13690 | clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE__CACHE_, NULL); |
| 13691 | clauses = c_finish_omp_clauses (clauses, C_ORT_ACC); |
| 13692 | |
| 13693 | c_parser_skip_to_pragma_eol (parser); |
| 13694 | |
| 13695 | stmt = make_node (OACC_CACHE); |
| 13696 | TREE_TYPE (stmt) = void_type_node; |
| 13697 | OACC_CACHE_CLAUSES (stmt) = clauses; |
| 13698 | SET_EXPR_LOCATION (stmt, loc); |
| 13699 | add_stmt (stmt); |
| 13700 | |
| 13701 | return stmt; |
| 13702 | } |
| 13703 | |
| 13704 | /* OpenACC 2.0: |
| 13705 | # pragma acc data oacc-data-clause[optseq] new-line |
| 13706 | structured-block |
| 13707 | |
| 13708 | LOC is the location of the #pragma token. |
| 13709 | */ |
| 13710 | |
| 13711 | #define OACC_DATA_CLAUSE_MASK \ |
| 13712 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \ |
| 13713 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ |
| 13714 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ |
| 13715 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ |
| 13716 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \ |
| 13717 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ |
| 13718 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ |
| 13719 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \ |
| 13720 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \ |
| 13721 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \ |
| 13722 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) ) |
| 13723 | |
| 13724 | static tree |
| 13725 | c_parser_oacc_data (location_t loc, c_parser *parser, bool *if_p) |
| 13726 | { |
| 13727 | tree stmt, clauses, block; |
| 13728 | |
| 13729 | clauses = c_parser_oacc_all_clauses (parser, OACC_DATA_CLAUSE_MASK, |
| 13730 | "#pragma acc data" ); |
| 13731 | |
| 13732 | block = c_begin_omp_parallel (); |
| 13733 | add_stmt (c_parser_omp_structured_block (parser, if_p)); |
| 13734 | |
| 13735 | stmt = c_finish_oacc_data (loc, clauses, block); |
| 13736 | |
| 13737 | return stmt; |
| 13738 | } |
| 13739 | |
| 13740 | /* OpenACC 2.0: |
| 13741 | # pragma acc declare oacc-data-clause[optseq] new-line |
| 13742 | */ |
| 13743 | |
| 13744 | #define OACC_DECLARE_CLAUSE_MASK \ |
| 13745 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \ |
| 13746 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ |
| 13747 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ |
| 13748 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ |
| 13749 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \ |
| 13750 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE_RESIDENT) \ |
| 13751 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_LINK) \ |
| 13752 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ |
| 13753 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \ |
| 13754 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \ |
| 13755 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \ |
| 13756 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) ) |
| 13757 | |
| 13758 | static void |
| 13759 | c_parser_oacc_declare (c_parser *parser) |
| 13760 | { |
| 13761 | location_t pragma_loc = c_parser_peek_token (parser)->location; |
| 13762 | tree clauses, stmt, t, decl; |
| 13763 | |
| 13764 | bool error = false; |
| 13765 | |
| 13766 | c_parser_consume_pragma (parser); |
| 13767 | |
| 13768 | clauses = c_parser_oacc_all_clauses (parser, OACC_DECLARE_CLAUSE_MASK, |
| 13769 | "#pragma acc declare" ); |
| 13770 | if (!clauses) |
| 13771 | { |
| 13772 | error_at (pragma_loc, |
| 13773 | "no valid clauses specified in %<#pragma acc declare%>" ); |
| 13774 | return; |
| 13775 | } |
| 13776 | |
| 13777 | for (t = clauses; t; t = OMP_CLAUSE_CHAIN (t)) |
| 13778 | { |
| 13779 | location_t loc = OMP_CLAUSE_LOCATION (t); |
| 13780 | decl = OMP_CLAUSE_DECL (t); |
| 13781 | if (!DECL_P (decl)) |
| 13782 | { |
| 13783 | error_at (loc, "array section in %<#pragma acc declare%>" ); |
| 13784 | error = true; |
| 13785 | continue; |
| 13786 | } |
| 13787 | |
| 13788 | switch (OMP_CLAUSE_MAP_KIND (t)) |
| 13789 | { |
| 13790 | case GOMP_MAP_FIRSTPRIVATE_POINTER: |
| 13791 | case GOMP_MAP_FORCE_ALLOC: |
| 13792 | case GOMP_MAP_FORCE_TO: |
| 13793 | case GOMP_MAP_FORCE_DEVICEPTR: |
| 13794 | case GOMP_MAP_DEVICE_RESIDENT: |
| 13795 | break; |
| 13796 | |
| 13797 | case GOMP_MAP_LINK: |
| 13798 | if (!global_bindings_p () |
| 13799 | && (TREE_STATIC (decl) |
| 13800 | || !DECL_EXTERNAL (decl))) |
| 13801 | { |
| 13802 | error_at (loc, |
| 13803 | "%qD must be a global variable in " |
| 13804 | "%<#pragma acc declare link%>" , |
| 13805 | decl); |
| 13806 | error = true; |
| 13807 | continue; |
| 13808 | } |
| 13809 | break; |
| 13810 | |
| 13811 | default: |
| 13812 | if (global_bindings_p ()) |
| 13813 | { |
| 13814 | error_at (loc, "invalid OpenACC clause at file scope" ); |
| 13815 | error = true; |
| 13816 | continue; |
| 13817 | } |
| 13818 | if (DECL_EXTERNAL (decl)) |
| 13819 | { |
| 13820 | error_at (loc, |
| 13821 | "invalid use of %<extern%> variable %qD " |
| 13822 | "in %<#pragma acc declare%>" , decl); |
| 13823 | error = true; |
| 13824 | continue; |
| 13825 | } |
| 13826 | else if (TREE_PUBLIC (decl)) |
| 13827 | { |
| 13828 | error_at (loc, |
| 13829 | "invalid use of %<global%> variable %qD " |
| 13830 | "in %<#pragma acc declare%>" , decl); |
| 13831 | error = true; |
| 13832 | continue; |
| 13833 | } |
| 13834 | break; |
| 13835 | } |
| 13836 | |
| 13837 | if (lookup_attribute ("omp declare target" , DECL_ATTRIBUTES (decl)) |
| 13838 | || lookup_attribute ("omp declare target link" , |
| 13839 | DECL_ATTRIBUTES (decl))) |
| 13840 | { |
| 13841 | error_at (loc, "variable %qD used more than once with " |
| 13842 | "%<#pragma acc declare%>" , decl); |
| 13843 | error = true; |
| 13844 | continue; |
| 13845 | } |
| 13846 | |
| 13847 | if (!error) |
| 13848 | { |
| 13849 | tree id; |
| 13850 | |
| 13851 | if (OMP_CLAUSE_MAP_KIND (t) == GOMP_MAP_LINK) |
| 13852 | id = get_identifier ("omp declare target link" ); |
| 13853 | else |
| 13854 | id = get_identifier ("omp declare target" ); |
| 13855 | |
| 13856 | DECL_ATTRIBUTES (decl) |
| 13857 | = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (decl)); |
| 13858 | |
| 13859 | if (global_bindings_p ()) |
| 13860 | { |
| 13861 | symtab_node *node = symtab_node::get (decl); |
| 13862 | if (node != NULL) |
| 13863 | { |
| 13864 | node->offloadable = 1; |
| 13865 | if (ENABLE_OFFLOADING) |
| 13866 | { |
| 13867 | g->have_offload = true; |
| 13868 | if (is_a <varpool_node *> (node)) |
| 13869 | vec_safe_push (offload_vars, decl); |
| 13870 | } |
| 13871 | } |
| 13872 | } |
| 13873 | } |
| 13874 | } |
| 13875 | |
| 13876 | if (error || global_bindings_p ()) |
| 13877 | return; |
| 13878 | |
| 13879 | stmt = make_node (OACC_DECLARE); |
| 13880 | TREE_TYPE (stmt) = void_type_node; |
| 13881 | OACC_DECLARE_CLAUSES (stmt) = clauses; |
| 13882 | SET_EXPR_LOCATION (stmt, pragma_loc); |
| 13883 | |
| 13884 | add_stmt (stmt); |
| 13885 | |
| 13886 | return; |
| 13887 | } |
| 13888 | |
| 13889 | /* OpenACC 2.0: |
| 13890 | # pragma acc enter data oacc-enter-data-clause[optseq] new-line |
| 13891 | |
| 13892 | or |
| 13893 | |
| 13894 | # pragma acc exit data oacc-exit-data-clause[optseq] new-line |
| 13895 | |
| 13896 | |
| 13897 | LOC is the location of the #pragma token. |
| 13898 | */ |
| 13899 | |
| 13900 | #define OACC_ENTER_DATA_CLAUSE_MASK \ |
| 13901 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ |
| 13902 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ |
| 13903 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ |
| 13904 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ |
| 13905 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \ |
| 13906 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \ |
| 13907 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) |
| 13908 | |
| 13909 | #define OACC_EXIT_DATA_CLAUSE_MASK \ |
| 13910 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ |
| 13911 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ |
| 13912 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ |
| 13913 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DELETE) \ |
| 13914 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) |
| 13915 | |
| 13916 | static void |
| 13917 | c_parser_oacc_enter_exit_data (c_parser *parser, bool enter) |
| 13918 | { |
| 13919 | location_t loc = c_parser_peek_token (parser)->location; |
| 13920 | tree clauses, stmt; |
| 13921 | const char *p = "" ; |
| 13922 | |
| 13923 | c_parser_consume_pragma (parser); |
| 13924 | |
| 13925 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 13926 | { |
| 13927 | p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 13928 | c_parser_consume_token (parser); |
| 13929 | } |
| 13930 | |
| 13931 | if (strcmp (p, "data" ) != 0) |
| 13932 | { |
| 13933 | error_at (loc, "expected %<data%> after %<#pragma acc %s%>" , |
| 13934 | enter ? "enter" : "exit" ); |
| 13935 | parser->error = true; |
| 13936 | c_parser_skip_to_pragma_eol (parser); |
| 13937 | return; |
| 13938 | } |
| 13939 | |
| 13940 | if (enter) |
| 13941 | clauses = c_parser_oacc_all_clauses (parser, OACC_ENTER_DATA_CLAUSE_MASK, |
| 13942 | "#pragma acc enter data" ); |
| 13943 | else |
| 13944 | clauses = c_parser_oacc_all_clauses (parser, OACC_EXIT_DATA_CLAUSE_MASK, |
| 13945 | "#pragma acc exit data" ); |
| 13946 | |
| 13947 | if (omp_find_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE) |
| 13948 | { |
| 13949 | error_at (loc, "%<#pragma acc %s data%> has no data movement clause" , |
| 13950 | enter ? "enter" : "exit" ); |
| 13951 | return; |
| 13952 | } |
| 13953 | |
| 13954 | stmt = enter ? make_node (OACC_ENTER_DATA) : make_node (OACC_EXIT_DATA); |
| 13955 | TREE_TYPE (stmt) = void_type_node; |
| 13956 | OMP_STANDALONE_CLAUSES (stmt) = clauses; |
| 13957 | SET_EXPR_LOCATION (stmt, loc); |
| 13958 | add_stmt (stmt); |
| 13959 | } |
| 13960 | |
| 13961 | |
| 13962 | /* OpenACC 2.0: |
| 13963 | # pragma acc host_data oacc-data-clause[optseq] new-line |
| 13964 | structured-block |
| 13965 | */ |
| 13966 | |
| 13967 | #define OACC_HOST_DATA_CLAUSE_MASK \ |
| 13968 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_USE_DEVICE) ) |
| 13969 | |
| 13970 | static tree |
| 13971 | c_parser_oacc_host_data (location_t loc, c_parser *parser, bool *if_p) |
| 13972 | { |
| 13973 | tree stmt, clauses, block; |
| 13974 | |
| 13975 | clauses = c_parser_oacc_all_clauses (parser, OACC_HOST_DATA_CLAUSE_MASK, |
| 13976 | "#pragma acc host_data" ); |
| 13977 | |
| 13978 | block = c_begin_omp_parallel (); |
| 13979 | add_stmt (c_parser_omp_structured_block (parser, if_p)); |
| 13980 | stmt = c_finish_oacc_host_data (loc, clauses, block); |
| 13981 | return stmt; |
| 13982 | } |
| 13983 | |
| 13984 | |
| 13985 | /* OpenACC 2.0: |
| 13986 | |
| 13987 | # pragma acc loop oacc-loop-clause[optseq] new-line |
| 13988 | structured-block |
| 13989 | |
| 13990 | LOC is the location of the #pragma token. |
| 13991 | */ |
| 13992 | |
| 13993 | #define OACC_LOOP_CLAUSE_MASK \ |
| 13994 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COLLAPSE) \ |
| 13995 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \ |
| 13996 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \ |
| 13997 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \ |
| 13998 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \ |
| 13999 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \ |
| 14000 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_AUTO) \ |
| 14001 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_INDEPENDENT) \ |
| 14002 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) \ |
| 14003 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_TILE) ) |
| 14004 | static tree |
| 14005 | c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name, |
| 14006 | omp_clause_mask mask, tree *cclauses, bool *if_p) |
| 14007 | { |
| 14008 | bool is_parallel = ((mask >> PRAGMA_OACC_CLAUSE_REDUCTION) & 1) == 1; |
| 14009 | |
| 14010 | strcat (p_name, " loop" ); |
| 14011 | mask |= OACC_LOOP_CLAUSE_MASK; |
| 14012 | |
| 14013 | tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name, |
| 14014 | cclauses == NULL); |
| 14015 | if (cclauses) |
| 14016 | { |
| 14017 | clauses = c_oacc_split_loop_clauses (clauses, cclauses, is_parallel); |
| 14018 | if (*cclauses) |
| 14019 | *cclauses = c_finish_omp_clauses (*cclauses, C_ORT_ACC); |
| 14020 | if (clauses) |
| 14021 | clauses = c_finish_omp_clauses (clauses, C_ORT_ACC); |
| 14022 | } |
| 14023 | |
| 14024 | tree block = c_begin_compound_stmt (true); |
| 14025 | tree stmt = c_parser_omp_for_loop (loc, parser, OACC_LOOP, clauses, NULL, |
| 14026 | if_p); |
| 14027 | block = c_end_compound_stmt (loc, block, true); |
| 14028 | add_stmt (block); |
| 14029 | |
| 14030 | return stmt; |
| 14031 | } |
| 14032 | |
| 14033 | /* OpenACC 2.0: |
| 14034 | # pragma acc kernels oacc-kernels-clause[optseq] new-line |
| 14035 | structured-block |
| 14036 | |
| 14037 | or |
| 14038 | |
| 14039 | # pragma acc parallel oacc-parallel-clause[optseq] new-line |
| 14040 | structured-block |
| 14041 | |
| 14042 | LOC is the location of the #pragma token. |
| 14043 | */ |
| 14044 | |
| 14045 | #define OACC_KERNELS_CLAUSE_MASK \ |
| 14046 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ |
| 14047 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \ |
| 14048 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ |
| 14049 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ |
| 14050 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ |
| 14051 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \ |
| 14052 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \ |
| 14053 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ |
| 14054 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ |
| 14055 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \ |
| 14056 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \ |
| 14057 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \ |
| 14058 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \ |
| 14059 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) |
| 14060 | |
| 14061 | #define OACC_PARALLEL_CLAUSE_MASK \ |
| 14062 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ |
| 14063 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPY) \ |
| 14064 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYIN) \ |
| 14065 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_COPYOUT) \ |
| 14066 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_CREATE) \ |
| 14067 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEFAULT) \ |
| 14068 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICEPTR) \ |
| 14069 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ |
| 14070 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRIVATE) \ |
| 14071 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_FIRSTPRIVATE) \ |
| 14072 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_GANGS) \ |
| 14073 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_NUM_WORKERS) \ |
| 14074 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT) \ |
| 14075 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPY) \ |
| 14076 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYIN) \ |
| 14077 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_COPYOUT) \ |
| 14078 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_PRESENT_OR_CREATE) \ |
| 14079 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_REDUCTION) \ |
| 14080 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR_LENGTH) \ |
| 14081 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) |
| 14082 | |
| 14083 | static tree |
| 14084 | c_parser_oacc_kernels_parallel (location_t loc, c_parser *parser, |
| 14085 | enum pragma_kind p_kind, char *p_name, |
| 14086 | bool *if_p) |
| 14087 | { |
| 14088 | omp_clause_mask mask; |
| 14089 | enum tree_code code; |
| 14090 | switch (p_kind) |
| 14091 | { |
| 14092 | case PRAGMA_OACC_KERNELS: |
| 14093 | strcat (p_name, " kernels" ); |
| 14094 | mask = OACC_KERNELS_CLAUSE_MASK; |
| 14095 | code = OACC_KERNELS; |
| 14096 | break; |
| 14097 | case PRAGMA_OACC_PARALLEL: |
| 14098 | strcat (p_name, " parallel" ); |
| 14099 | mask = OACC_PARALLEL_CLAUSE_MASK; |
| 14100 | code = OACC_PARALLEL; |
| 14101 | break; |
| 14102 | default: |
| 14103 | gcc_unreachable (); |
| 14104 | } |
| 14105 | |
| 14106 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 14107 | { |
| 14108 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 14109 | if (strcmp (p, "loop" ) == 0) |
| 14110 | { |
| 14111 | c_parser_consume_token (parser); |
| 14112 | tree block = c_begin_omp_parallel (); |
| 14113 | tree clauses; |
| 14114 | c_parser_oacc_loop (loc, parser, p_name, mask, &clauses, if_p); |
| 14115 | return c_finish_omp_construct (loc, code, block, clauses); |
| 14116 | } |
| 14117 | } |
| 14118 | |
| 14119 | tree clauses = c_parser_oacc_all_clauses (parser, mask, p_name); |
| 14120 | |
| 14121 | tree block = c_begin_omp_parallel (); |
| 14122 | add_stmt (c_parser_omp_structured_block (parser, if_p)); |
| 14123 | |
| 14124 | return c_finish_omp_construct (loc, code, block, clauses); |
| 14125 | } |
| 14126 | |
| 14127 | /* OpenACC 2.0: |
| 14128 | # pragma acc routine oacc-routine-clause[optseq] new-line |
| 14129 | function-definition |
| 14130 | |
| 14131 | # pragma acc routine ( name ) oacc-routine-clause[optseq] new-line |
| 14132 | */ |
| 14133 | |
| 14134 | #define OACC_ROUTINE_CLAUSE_MASK \ |
| 14135 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_GANG) \ |
| 14136 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WORKER) \ |
| 14137 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_VECTOR) \ |
| 14138 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SEQ) ) |
| 14139 | |
| 14140 | /* Parse an OpenACC routine directive. For named directives, we apply |
| 14141 | immediately to the named function. For unnamed ones we then parse |
| 14142 | a declaration or definition, which must be for a function. */ |
| 14143 | |
| 14144 | static void |
| 14145 | c_parser_oacc_routine (c_parser *parser, enum pragma_context context) |
| 14146 | { |
| 14147 | gcc_checking_assert (context == pragma_external); |
| 14148 | |
| 14149 | oacc_routine_data data; |
| 14150 | data.error_seen = false; |
| 14151 | data.fndecl_seen = false; |
| 14152 | data.clauses = NULL_TREE; |
| 14153 | data.loc = c_parser_peek_token (parser)->location; |
| 14154 | |
| 14155 | c_parser_consume_pragma (parser); |
| 14156 | |
| 14157 | /* Look for optional '( name )'. */ |
| 14158 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 14159 | { |
| 14160 | c_parser_consume_token (parser); /* '(' */ |
| 14161 | |
| 14162 | tree decl = NULL_TREE; |
| 14163 | c_token *name_token = c_parser_peek_token (parser); |
| 14164 | location_t name_loc = name_token->location; |
| 14165 | if (name_token->type == CPP_NAME |
| 14166 | && (name_token->id_kind == C_ID_ID |
| 14167 | || name_token->id_kind == C_ID_TYPENAME)) |
| 14168 | { |
| 14169 | decl = lookup_name (name_token->value); |
| 14170 | if (!decl) |
| 14171 | error_at (name_loc, |
| 14172 | "%qE has not been declared" , name_token->value); |
| 14173 | c_parser_consume_token (parser); |
| 14174 | } |
| 14175 | else |
| 14176 | c_parser_error (parser, "expected function name" ); |
| 14177 | |
| 14178 | if (!decl |
| 14179 | || !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>" )) |
| 14180 | { |
| 14181 | c_parser_skip_to_pragma_eol (parser, false); |
| 14182 | return; |
| 14183 | } |
| 14184 | |
| 14185 | data.clauses |
| 14186 | = c_parser_oacc_all_clauses (parser, OACC_ROUTINE_CLAUSE_MASK, |
| 14187 | "#pragma acc routine" ); |
| 14188 | |
| 14189 | if (TREE_CODE (decl) != FUNCTION_DECL) |
| 14190 | { |
| 14191 | error_at (name_loc, "%qD does not refer to a function" , decl); |
| 14192 | return; |
| 14193 | } |
| 14194 | |
| 14195 | c_finish_oacc_routine (&data, decl, false); |
| 14196 | } |
| 14197 | else /* No optional '( name )'. */ |
| 14198 | { |
| 14199 | data.clauses |
| 14200 | = c_parser_oacc_all_clauses (parser, OACC_ROUTINE_CLAUSE_MASK, |
| 14201 | "#pragma acc routine" ); |
| 14202 | |
| 14203 | /* Emit a helpful diagnostic if there's another pragma following this |
| 14204 | one. Also don't allow a static assertion declaration, as in the |
| 14205 | following we'll just parse a *single* "declaration or function |
| 14206 | definition", and the static assertion counts an one. */ |
| 14207 | if (c_parser_next_token_is (parser, CPP_PRAGMA) |
| 14208 | || c_parser_next_token_is_keyword (parser, RID_STATIC_ASSERT)) |
| 14209 | { |
| 14210 | error_at (data.loc, |
| 14211 | "%<#pragma acc routine%> not immediately followed by" |
| 14212 | " function declaration or definition" ); |
| 14213 | /* ..., and then just keep going. */ |
| 14214 | return; |
| 14215 | } |
| 14216 | |
| 14217 | /* We only have to consider the pragma_external case here. */ |
| 14218 | if (c_parser_next_token_is (parser, CPP_KEYWORD) |
| 14219 | && c_parser_peek_token (parser)->keyword == RID_EXTENSION) |
| 14220 | { |
| 14221 | int ext = disable_extension_diagnostics (); |
| 14222 | do |
| 14223 | c_parser_consume_token (parser); |
| 14224 | while (c_parser_next_token_is (parser, CPP_KEYWORD) |
| 14225 | && c_parser_peek_token (parser)->keyword == RID_EXTENSION); |
| 14226 | c_parser_declaration_or_fndef (parser, true, true, true, false, true, |
| 14227 | NULL, vNULL, &data); |
| 14228 | restore_extension_diagnostics (ext); |
| 14229 | } |
| 14230 | else |
| 14231 | c_parser_declaration_or_fndef (parser, true, true, true, false, true, |
| 14232 | NULL, vNULL, &data); |
| 14233 | } |
| 14234 | } |
| 14235 | |
| 14236 | /* Finalize an OpenACC routine pragma, applying it to FNDECL. |
| 14237 | IS_DEFN is true if we're applying it to the definition. */ |
| 14238 | |
| 14239 | static void |
| 14240 | c_finish_oacc_routine (struct oacc_routine_data *data, tree fndecl, |
| 14241 | bool is_defn) |
| 14242 | { |
| 14243 | /* Keep going if we're in error reporting mode. */ |
| 14244 | if (data->error_seen |
| 14245 | || fndecl == error_mark_node) |
| 14246 | return; |
| 14247 | |
| 14248 | if (data->fndecl_seen) |
| 14249 | { |
| 14250 | error_at (data->loc, |
| 14251 | "%<#pragma acc routine%> not immediately followed by" |
| 14252 | " a single function declaration or definition" ); |
| 14253 | data->error_seen = true; |
| 14254 | return; |
| 14255 | } |
| 14256 | if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL) |
| 14257 | { |
| 14258 | error_at (data->loc, |
| 14259 | "%<#pragma acc routine%> not immediately followed by" |
| 14260 | " function declaration or definition" ); |
| 14261 | data->error_seen = true; |
| 14262 | return; |
| 14263 | } |
| 14264 | |
| 14265 | if (oacc_get_fn_attrib (fndecl)) |
| 14266 | { |
| 14267 | error_at (data->loc, |
| 14268 | "%<#pragma acc routine%> already applied to %qD" , fndecl); |
| 14269 | data->error_seen = true; |
| 14270 | return; |
| 14271 | } |
| 14272 | |
| 14273 | if (TREE_USED (fndecl) || (!is_defn && DECL_SAVED_TREE (fndecl))) |
| 14274 | { |
| 14275 | error_at (data->loc, |
| 14276 | TREE_USED (fndecl) |
| 14277 | ? G_("%<#pragma acc routine%> must be applied before use" ) |
| 14278 | : G_("%<#pragma acc routine%> must be applied before " |
| 14279 | "definition" )); |
| 14280 | data->error_seen = true; |
| 14281 | return; |
| 14282 | } |
| 14283 | |
| 14284 | /* Process the routine's dimension clauses. */ |
| 14285 | tree dims = oacc_build_routine_dims (data->clauses); |
| 14286 | oacc_replace_fn_attrib (fndecl, dims); |
| 14287 | |
| 14288 | /* Add an "omp declare target" attribute. */ |
| 14289 | DECL_ATTRIBUTES (fndecl) |
| 14290 | = tree_cons (get_identifier ("omp declare target" ), |
| 14291 | NULL_TREE, DECL_ATTRIBUTES (fndecl)); |
| 14292 | |
| 14293 | /* Remember that we've used this "#pragma acc routine". */ |
| 14294 | data->fndecl_seen = true; |
| 14295 | } |
| 14296 | |
| 14297 | /* OpenACC 2.0: |
| 14298 | # pragma acc update oacc-update-clause[optseq] new-line |
| 14299 | */ |
| 14300 | |
| 14301 | #define OACC_UPDATE_CLAUSE_MASK \ |
| 14302 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) \ |
| 14303 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_DEVICE) \ |
| 14304 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_HOST) \ |
| 14305 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_IF) \ |
| 14306 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_SELF) \ |
| 14307 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_WAIT) ) |
| 14308 | |
| 14309 | static void |
| 14310 | c_parser_oacc_update (c_parser *parser) |
| 14311 | { |
| 14312 | location_t loc = c_parser_peek_token (parser)->location; |
| 14313 | |
| 14314 | c_parser_consume_pragma (parser); |
| 14315 | |
| 14316 | tree clauses = c_parser_oacc_all_clauses (parser, OACC_UPDATE_CLAUSE_MASK, |
| 14317 | "#pragma acc update" ); |
| 14318 | if (omp_find_clause (clauses, OMP_CLAUSE_MAP) == NULL_TREE) |
| 14319 | { |
| 14320 | error_at (loc, |
| 14321 | "%<#pragma acc update%> must contain at least one " |
| 14322 | "%<device%> or %<host%> or %<self%> clause" ); |
| 14323 | return; |
| 14324 | } |
| 14325 | |
| 14326 | if (parser->error) |
| 14327 | return; |
| 14328 | |
| 14329 | tree stmt = make_node (OACC_UPDATE); |
| 14330 | TREE_TYPE (stmt) = void_type_node; |
| 14331 | OACC_UPDATE_CLAUSES (stmt) = clauses; |
| 14332 | SET_EXPR_LOCATION (stmt, loc); |
| 14333 | add_stmt (stmt); |
| 14334 | } |
| 14335 | |
| 14336 | /* OpenACC 2.0: |
| 14337 | # pragma acc wait [(intseq)] oacc-wait-clause[optseq] new-line |
| 14338 | |
| 14339 | LOC is the location of the #pragma token. |
| 14340 | */ |
| 14341 | |
| 14342 | #define OACC_WAIT_CLAUSE_MASK \ |
| 14343 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OACC_CLAUSE_ASYNC) ) |
| 14344 | |
| 14345 | static tree |
| 14346 | c_parser_oacc_wait (location_t loc, c_parser *parser, char *p_name) |
| 14347 | { |
| 14348 | tree clauses, list = NULL_TREE, stmt = NULL_TREE; |
| 14349 | |
| 14350 | if (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN) |
| 14351 | list = c_parser_oacc_wait_list (parser, loc, list); |
| 14352 | |
| 14353 | strcpy (p_name, " wait" ); |
| 14354 | clauses = c_parser_oacc_all_clauses (parser, OACC_WAIT_CLAUSE_MASK, p_name); |
| 14355 | stmt = c_finish_oacc_wait (loc, list, clauses); |
| 14356 | add_stmt (stmt); |
| 14357 | |
| 14358 | return stmt; |
| 14359 | } |
| 14360 | |
| 14361 | /* OpenMP 2.5: |
| 14362 | # pragma omp atomic new-line |
| 14363 | expression-stmt |
| 14364 | |
| 14365 | expression-stmt: |
| 14366 | x binop= expr | x++ | ++x | x-- | --x |
| 14367 | binop: |
| 14368 | +, *, -, /, &, ^, |, <<, >> |
| 14369 | |
| 14370 | where x is an lvalue expression with scalar type. |
| 14371 | |
| 14372 | OpenMP 3.1: |
| 14373 | # pragma omp atomic new-line |
| 14374 | update-stmt |
| 14375 | |
| 14376 | # pragma omp atomic read new-line |
| 14377 | read-stmt |
| 14378 | |
| 14379 | # pragma omp atomic write new-line |
| 14380 | write-stmt |
| 14381 | |
| 14382 | # pragma omp atomic update new-line |
| 14383 | update-stmt |
| 14384 | |
| 14385 | # pragma omp atomic capture new-line |
| 14386 | capture-stmt |
| 14387 | |
| 14388 | # pragma omp atomic capture new-line |
| 14389 | capture-block |
| 14390 | |
| 14391 | read-stmt: |
| 14392 | v = x |
| 14393 | write-stmt: |
| 14394 | x = expr |
| 14395 | update-stmt: |
| 14396 | expression-stmt | x = x binop expr |
| 14397 | capture-stmt: |
| 14398 | v = expression-stmt |
| 14399 | capture-block: |
| 14400 | { v = x; update-stmt; } | { update-stmt; v = x; } |
| 14401 | |
| 14402 | OpenMP 4.0: |
| 14403 | update-stmt: |
| 14404 | expression-stmt | x = x binop expr | x = expr binop x |
| 14405 | capture-stmt: |
| 14406 | v = update-stmt |
| 14407 | capture-block: |
| 14408 | { v = x; update-stmt; } | { update-stmt; v = x; } | { v = x; x = expr; } |
| 14409 | |
| 14410 | where x and v are lvalue expressions with scalar type. |
| 14411 | |
| 14412 | LOC is the location of the #pragma token. */ |
| 14413 | |
| 14414 | static void |
| 14415 | c_parser_omp_atomic (location_t loc, c_parser *parser) |
| 14416 | { |
| 14417 | tree lhs = NULL_TREE, rhs = NULL_TREE, v = NULL_TREE; |
| 14418 | tree lhs1 = NULL_TREE, rhs1 = NULL_TREE; |
| 14419 | tree stmt, orig_lhs, unfolded_lhs = NULL_TREE, unfolded_lhs1 = NULL_TREE; |
| 14420 | enum tree_code code = OMP_ATOMIC, opcode = NOP_EXPR; |
| 14421 | struct c_expr expr; |
| 14422 | location_t eloc; |
| 14423 | bool structured_block = false; |
| 14424 | bool swapped = false; |
| 14425 | bool seq_cst = false; |
| 14426 | bool non_lvalue_p; |
| 14427 | |
| 14428 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 14429 | { |
| 14430 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 14431 | if (!strcmp (p, "seq_cst" )) |
| 14432 | { |
| 14433 | seq_cst = true; |
| 14434 | c_parser_consume_token (parser); |
| 14435 | if (c_parser_next_token_is (parser, CPP_COMMA) |
| 14436 | && c_parser_peek_2nd_token (parser)->type == CPP_NAME) |
| 14437 | c_parser_consume_token (parser); |
| 14438 | } |
| 14439 | } |
| 14440 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 14441 | { |
| 14442 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 14443 | |
| 14444 | if (!strcmp (p, "read" )) |
| 14445 | code = OMP_ATOMIC_READ; |
| 14446 | else if (!strcmp (p, "write" )) |
| 14447 | code = NOP_EXPR; |
| 14448 | else if (!strcmp (p, "update" )) |
| 14449 | code = OMP_ATOMIC; |
| 14450 | else if (!strcmp (p, "capture" )) |
| 14451 | code = OMP_ATOMIC_CAPTURE_NEW; |
| 14452 | else |
| 14453 | p = NULL; |
| 14454 | if (p) |
| 14455 | c_parser_consume_token (parser); |
| 14456 | } |
| 14457 | if (!seq_cst) |
| 14458 | { |
| 14459 | if (c_parser_next_token_is (parser, CPP_COMMA) |
| 14460 | && c_parser_peek_2nd_token (parser)->type == CPP_NAME) |
| 14461 | c_parser_consume_token (parser); |
| 14462 | |
| 14463 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 14464 | { |
| 14465 | const char *p |
| 14466 | = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 14467 | if (!strcmp (p, "seq_cst" )) |
| 14468 | { |
| 14469 | seq_cst = true; |
| 14470 | c_parser_consume_token (parser); |
| 14471 | } |
| 14472 | } |
| 14473 | } |
| 14474 | c_parser_skip_to_pragma_eol (parser); |
| 14475 | |
| 14476 | switch (code) |
| 14477 | { |
| 14478 | case OMP_ATOMIC_READ: |
| 14479 | case NOP_EXPR: /* atomic write */ |
| 14480 | v = c_parser_cast_expression (parser, NULL).value; |
| 14481 | non_lvalue_p = !lvalue_p (v); |
| 14482 | v = c_fully_fold (v, false, NULL); |
| 14483 | if (v == error_mark_node) |
| 14484 | goto saw_error; |
| 14485 | if (non_lvalue_p) |
| 14486 | v = non_lvalue (v); |
| 14487 | loc = c_parser_peek_token (parser)->location; |
| 14488 | if (!c_parser_require (parser, CPP_EQ, "expected %<=%>" )) |
| 14489 | goto saw_error; |
| 14490 | if (code == NOP_EXPR) |
| 14491 | { |
| 14492 | lhs = c_parser_expression (parser).value; |
| 14493 | lhs = c_fully_fold (lhs, false, NULL); |
| 14494 | if (lhs == error_mark_node) |
| 14495 | goto saw_error; |
| 14496 | } |
| 14497 | else |
| 14498 | { |
| 14499 | lhs = c_parser_cast_expression (parser, NULL).value; |
| 14500 | non_lvalue_p = !lvalue_p (lhs); |
| 14501 | lhs = c_fully_fold (lhs, false, NULL); |
| 14502 | if (lhs == error_mark_node) |
| 14503 | goto saw_error; |
| 14504 | if (non_lvalue_p) |
| 14505 | lhs = non_lvalue (lhs); |
| 14506 | } |
| 14507 | if (code == NOP_EXPR) |
| 14508 | { |
| 14509 | /* atomic write is represented by OMP_ATOMIC with NOP_EXPR |
| 14510 | opcode. */ |
| 14511 | code = OMP_ATOMIC; |
| 14512 | rhs = lhs; |
| 14513 | lhs = v; |
| 14514 | v = NULL_TREE; |
| 14515 | } |
| 14516 | goto done; |
| 14517 | case OMP_ATOMIC_CAPTURE_NEW: |
| 14518 | if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 14519 | { |
| 14520 | c_parser_consume_token (parser); |
| 14521 | structured_block = true; |
| 14522 | } |
| 14523 | else |
| 14524 | { |
| 14525 | v = c_parser_cast_expression (parser, NULL).value; |
| 14526 | non_lvalue_p = !lvalue_p (v); |
| 14527 | v = c_fully_fold (v, false, NULL); |
| 14528 | if (v == error_mark_node) |
| 14529 | goto saw_error; |
| 14530 | if (non_lvalue_p) |
| 14531 | v = non_lvalue (v); |
| 14532 | if (!c_parser_require (parser, CPP_EQ, "expected %<=%>" )) |
| 14533 | goto saw_error; |
| 14534 | } |
| 14535 | break; |
| 14536 | default: |
| 14537 | break; |
| 14538 | } |
| 14539 | |
| 14540 | /* For structured_block case we don't know yet whether |
| 14541 | old or new x should be captured. */ |
| 14542 | restart: |
| 14543 | eloc = c_parser_peek_token (parser)->location; |
| 14544 | expr = c_parser_cast_expression (parser, NULL); |
| 14545 | lhs = expr.value; |
| 14546 | expr = default_function_array_conversion (eloc, expr); |
| 14547 | unfolded_lhs = expr.value; |
| 14548 | lhs = c_fully_fold (lhs, false, NULL); |
| 14549 | orig_lhs = lhs; |
| 14550 | switch (TREE_CODE (lhs)) |
| 14551 | { |
| 14552 | case ERROR_MARK: |
| 14553 | saw_error: |
| 14554 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 14555 | if (structured_block) |
| 14556 | { |
| 14557 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 14558 | c_parser_consume_token (parser); |
| 14559 | else if (code == OMP_ATOMIC_CAPTURE_NEW) |
| 14560 | { |
| 14561 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 14562 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 14563 | c_parser_consume_token (parser); |
| 14564 | } |
| 14565 | } |
| 14566 | return; |
| 14567 | |
| 14568 | case POSTINCREMENT_EXPR: |
| 14569 | if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block) |
| 14570 | code = OMP_ATOMIC_CAPTURE_OLD; |
| 14571 | /* FALLTHROUGH */ |
| 14572 | case PREINCREMENT_EXPR: |
| 14573 | lhs = TREE_OPERAND (lhs, 0); |
| 14574 | unfolded_lhs = NULL_TREE; |
| 14575 | opcode = PLUS_EXPR; |
| 14576 | rhs = integer_one_node; |
| 14577 | break; |
| 14578 | |
| 14579 | case POSTDECREMENT_EXPR: |
| 14580 | if (code == OMP_ATOMIC_CAPTURE_NEW && !structured_block) |
| 14581 | code = OMP_ATOMIC_CAPTURE_OLD; |
| 14582 | /* FALLTHROUGH */ |
| 14583 | case PREDECREMENT_EXPR: |
| 14584 | lhs = TREE_OPERAND (lhs, 0); |
| 14585 | unfolded_lhs = NULL_TREE; |
| 14586 | opcode = MINUS_EXPR; |
| 14587 | rhs = integer_one_node; |
| 14588 | break; |
| 14589 | |
| 14590 | case COMPOUND_EXPR: |
| 14591 | if (TREE_CODE (TREE_OPERAND (lhs, 0)) == SAVE_EXPR |
| 14592 | && TREE_CODE (TREE_OPERAND (lhs, 1)) == COMPOUND_EXPR |
| 14593 | && TREE_CODE (TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) == MODIFY_EXPR |
| 14594 | && TREE_OPERAND (TREE_OPERAND (lhs, 1), 1) == TREE_OPERAND (lhs, 0) |
| 14595 | && TREE_CODE (TREE_TYPE (TREE_OPERAND (TREE_OPERAND |
| 14596 | (TREE_OPERAND (lhs, 1), 0), 0))) |
| 14597 | == BOOLEAN_TYPE) |
| 14598 | /* Undo effects of boolean_increment for post {in,de}crement. */ |
| 14599 | lhs = TREE_OPERAND (TREE_OPERAND (lhs, 1), 0); |
| 14600 | /* FALLTHRU */ |
| 14601 | case MODIFY_EXPR: |
| 14602 | if (TREE_CODE (lhs) == MODIFY_EXPR |
| 14603 | && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == BOOLEAN_TYPE) |
| 14604 | { |
| 14605 | /* Undo effects of boolean_increment. */ |
| 14606 | if (integer_onep (TREE_OPERAND (lhs, 1))) |
| 14607 | { |
| 14608 | /* This is pre or post increment. */ |
| 14609 | rhs = TREE_OPERAND (lhs, 1); |
| 14610 | lhs = TREE_OPERAND (lhs, 0); |
| 14611 | unfolded_lhs = NULL_TREE; |
| 14612 | opcode = NOP_EXPR; |
| 14613 | if (code == OMP_ATOMIC_CAPTURE_NEW |
| 14614 | && !structured_block |
| 14615 | && TREE_CODE (orig_lhs) == COMPOUND_EXPR) |
| 14616 | code = OMP_ATOMIC_CAPTURE_OLD; |
| 14617 | break; |
| 14618 | } |
| 14619 | if (TREE_CODE (TREE_OPERAND (lhs, 1)) == TRUTH_NOT_EXPR |
| 14620 | && TREE_OPERAND (lhs, 0) |
| 14621 | == TREE_OPERAND (TREE_OPERAND (lhs, 1), 0)) |
| 14622 | { |
| 14623 | /* This is pre or post decrement. */ |
| 14624 | rhs = TREE_OPERAND (lhs, 1); |
| 14625 | lhs = TREE_OPERAND (lhs, 0); |
| 14626 | unfolded_lhs = NULL_TREE; |
| 14627 | opcode = NOP_EXPR; |
| 14628 | if (code == OMP_ATOMIC_CAPTURE_NEW |
| 14629 | && !structured_block |
| 14630 | && TREE_CODE (orig_lhs) == COMPOUND_EXPR) |
| 14631 | code = OMP_ATOMIC_CAPTURE_OLD; |
| 14632 | break; |
| 14633 | } |
| 14634 | } |
| 14635 | /* FALLTHRU */ |
| 14636 | default: |
| 14637 | if (!lvalue_p (unfolded_lhs)) |
| 14638 | lhs = non_lvalue (lhs); |
| 14639 | switch (c_parser_peek_token (parser)->type) |
| 14640 | { |
| 14641 | case CPP_MULT_EQ: |
| 14642 | opcode = MULT_EXPR; |
| 14643 | break; |
| 14644 | case CPP_DIV_EQ: |
| 14645 | opcode = TRUNC_DIV_EXPR; |
| 14646 | break; |
| 14647 | case CPP_PLUS_EQ: |
| 14648 | opcode = PLUS_EXPR; |
| 14649 | break; |
| 14650 | case CPP_MINUS_EQ: |
| 14651 | opcode = MINUS_EXPR; |
| 14652 | break; |
| 14653 | case CPP_LSHIFT_EQ: |
| 14654 | opcode = LSHIFT_EXPR; |
| 14655 | break; |
| 14656 | case CPP_RSHIFT_EQ: |
| 14657 | opcode = RSHIFT_EXPR; |
| 14658 | break; |
| 14659 | case CPP_AND_EQ: |
| 14660 | opcode = BIT_AND_EXPR; |
| 14661 | break; |
| 14662 | case CPP_OR_EQ: |
| 14663 | opcode = BIT_IOR_EXPR; |
| 14664 | break; |
| 14665 | case CPP_XOR_EQ: |
| 14666 | opcode = BIT_XOR_EXPR; |
| 14667 | break; |
| 14668 | case CPP_EQ: |
| 14669 | c_parser_consume_token (parser); |
| 14670 | eloc = c_parser_peek_token (parser)->location; |
| 14671 | expr = c_parser_expr_no_commas (parser, NULL, unfolded_lhs); |
| 14672 | rhs1 = expr.value; |
| 14673 | switch (TREE_CODE (rhs1)) |
| 14674 | { |
| 14675 | case MULT_EXPR: |
| 14676 | case TRUNC_DIV_EXPR: |
| 14677 | case RDIV_EXPR: |
| 14678 | case PLUS_EXPR: |
| 14679 | case MINUS_EXPR: |
| 14680 | case LSHIFT_EXPR: |
| 14681 | case RSHIFT_EXPR: |
| 14682 | case BIT_AND_EXPR: |
| 14683 | case BIT_IOR_EXPR: |
| 14684 | case BIT_XOR_EXPR: |
| 14685 | if (c_tree_equal (TREE_OPERAND (rhs1, 0), unfolded_lhs)) |
| 14686 | { |
| 14687 | opcode = TREE_CODE (rhs1); |
| 14688 | rhs = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL); |
| 14689 | rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL); |
| 14690 | goto stmt_done; |
| 14691 | } |
| 14692 | if (c_tree_equal (TREE_OPERAND (rhs1, 1), unfolded_lhs)) |
| 14693 | { |
| 14694 | opcode = TREE_CODE (rhs1); |
| 14695 | rhs = c_fully_fold (TREE_OPERAND (rhs1, 0), false, NULL); |
| 14696 | rhs1 = c_fully_fold (TREE_OPERAND (rhs1, 1), false, NULL); |
| 14697 | swapped = !commutative_tree_code (opcode); |
| 14698 | goto stmt_done; |
| 14699 | } |
| 14700 | break; |
| 14701 | case ERROR_MARK: |
| 14702 | goto saw_error; |
| 14703 | default: |
| 14704 | break; |
| 14705 | } |
| 14706 | if (c_parser_peek_token (parser)->type == CPP_SEMICOLON) |
| 14707 | { |
| 14708 | if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW) |
| 14709 | { |
| 14710 | code = OMP_ATOMIC_CAPTURE_OLD; |
| 14711 | v = lhs; |
| 14712 | lhs = NULL_TREE; |
| 14713 | expr = default_function_array_read_conversion (eloc, expr); |
| 14714 | unfolded_lhs1 = expr.value; |
| 14715 | lhs1 = c_fully_fold (unfolded_lhs1, false, NULL); |
| 14716 | rhs1 = NULL_TREE; |
| 14717 | c_parser_consume_token (parser); |
| 14718 | goto restart; |
| 14719 | } |
| 14720 | if (structured_block) |
| 14721 | { |
| 14722 | opcode = NOP_EXPR; |
| 14723 | expr = default_function_array_read_conversion (eloc, expr); |
| 14724 | rhs = c_fully_fold (expr.value, false, NULL); |
| 14725 | rhs1 = NULL_TREE; |
| 14726 | goto stmt_done; |
| 14727 | } |
| 14728 | } |
| 14729 | c_parser_error (parser, "invalid form of %<#pragma omp atomic%>" ); |
| 14730 | goto saw_error; |
| 14731 | default: |
| 14732 | c_parser_error (parser, |
| 14733 | "invalid operator for %<#pragma omp atomic%>" ); |
| 14734 | goto saw_error; |
| 14735 | } |
| 14736 | |
| 14737 | /* Arrange to pass the location of the assignment operator to |
| 14738 | c_finish_omp_atomic. */ |
| 14739 | loc = c_parser_peek_token (parser)->location; |
| 14740 | c_parser_consume_token (parser); |
| 14741 | eloc = c_parser_peek_token (parser)->location; |
| 14742 | expr = c_parser_expression (parser); |
| 14743 | expr = default_function_array_read_conversion (eloc, expr); |
| 14744 | rhs = expr.value; |
| 14745 | rhs = c_fully_fold (rhs, false, NULL); |
| 14746 | break; |
| 14747 | } |
| 14748 | stmt_done: |
| 14749 | if (structured_block && code == OMP_ATOMIC_CAPTURE_NEW) |
| 14750 | { |
| 14751 | if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>" )) |
| 14752 | goto saw_error; |
| 14753 | v = c_parser_cast_expression (parser, NULL).value; |
| 14754 | non_lvalue_p = !lvalue_p (v); |
| 14755 | v = c_fully_fold (v, false, NULL); |
| 14756 | if (v == error_mark_node) |
| 14757 | goto saw_error; |
| 14758 | if (non_lvalue_p) |
| 14759 | v = non_lvalue (v); |
| 14760 | if (!c_parser_require (parser, CPP_EQ, "expected %<=%>" )) |
| 14761 | goto saw_error; |
| 14762 | eloc = c_parser_peek_token (parser)->location; |
| 14763 | expr = c_parser_cast_expression (parser, NULL); |
| 14764 | lhs1 = expr.value; |
| 14765 | expr = default_function_array_read_conversion (eloc, expr); |
| 14766 | unfolded_lhs1 = expr.value; |
| 14767 | lhs1 = c_fully_fold (lhs1, false, NULL); |
| 14768 | if (lhs1 == error_mark_node) |
| 14769 | goto saw_error; |
| 14770 | if (!lvalue_p (unfolded_lhs1)) |
| 14771 | lhs1 = non_lvalue (lhs1); |
| 14772 | } |
| 14773 | if (structured_block) |
| 14774 | { |
| 14775 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>" ); |
| 14776 | c_parser_require (parser, CPP_CLOSE_BRACE, "expected %<}%>" ); |
| 14777 | } |
| 14778 | done: |
| 14779 | if (unfolded_lhs && unfolded_lhs1 |
| 14780 | && !c_tree_equal (unfolded_lhs, unfolded_lhs1)) |
| 14781 | { |
| 14782 | error ("%<#pragma omp atomic capture%> uses two different " |
| 14783 | "expressions for memory" ); |
| 14784 | stmt = error_mark_node; |
| 14785 | } |
| 14786 | else |
| 14787 | stmt = c_finish_omp_atomic (loc, code, opcode, lhs, rhs, v, lhs1, rhs1, |
| 14788 | swapped, seq_cst); |
| 14789 | if (stmt != error_mark_node) |
| 14790 | add_stmt (stmt); |
| 14791 | |
| 14792 | if (!structured_block) |
| 14793 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>" ); |
| 14794 | } |
| 14795 | |
| 14796 | |
| 14797 | /* OpenMP 2.5: |
| 14798 | # pragma omp barrier new-line |
| 14799 | */ |
| 14800 | |
| 14801 | static void |
| 14802 | c_parser_omp_barrier (c_parser *parser) |
| 14803 | { |
| 14804 | location_t loc = c_parser_peek_token (parser)->location; |
| 14805 | c_parser_consume_pragma (parser); |
| 14806 | c_parser_skip_to_pragma_eol (parser); |
| 14807 | |
| 14808 | c_finish_omp_barrier (loc); |
| 14809 | } |
| 14810 | |
| 14811 | /* OpenMP 2.5: |
| 14812 | # pragma omp critical [(name)] new-line |
| 14813 | structured-block |
| 14814 | |
| 14815 | OpenMP 4.5: |
| 14816 | # pragma omp critical [(name) [hint(expression)]] new-line |
| 14817 | |
| 14818 | LOC is the location of the #pragma itself. */ |
| 14819 | |
| 14820 | #define OMP_CRITICAL_CLAUSE_MASK \ |
| 14821 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_HINT) ) |
| 14822 | |
| 14823 | static tree |
| 14824 | c_parser_omp_critical (location_t loc, c_parser *parser, bool *if_p) |
| 14825 | { |
| 14826 | tree stmt, name = NULL_TREE, clauses = NULL_TREE; |
| 14827 | |
| 14828 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 14829 | { |
| 14830 | c_parser_consume_token (parser); |
| 14831 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 14832 | { |
| 14833 | name = c_parser_peek_token (parser)->value; |
| 14834 | c_parser_consume_token (parser); |
| 14835 | c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 14836 | } |
| 14837 | else |
| 14838 | c_parser_error (parser, "expected identifier" ); |
| 14839 | |
| 14840 | clauses = c_parser_omp_all_clauses (parser, |
| 14841 | OMP_CRITICAL_CLAUSE_MASK, |
| 14842 | "#pragma omp critical" ); |
| 14843 | } |
| 14844 | else |
| 14845 | { |
| 14846 | if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
| 14847 | c_parser_error (parser, "expected %<(%> or end of line" ); |
| 14848 | c_parser_skip_to_pragma_eol (parser); |
| 14849 | } |
| 14850 | |
| 14851 | stmt = c_parser_omp_structured_block (parser, if_p); |
| 14852 | return c_finish_omp_critical (loc, stmt, name, clauses); |
| 14853 | } |
| 14854 | |
| 14855 | /* OpenMP 2.5: |
| 14856 | # pragma omp flush flush-vars[opt] new-line |
| 14857 | |
| 14858 | flush-vars: |
| 14859 | ( variable-list ) */ |
| 14860 | |
| 14861 | static void |
| 14862 | c_parser_omp_flush (c_parser *parser) |
| 14863 | { |
| 14864 | location_t loc = c_parser_peek_token (parser)->location; |
| 14865 | c_parser_consume_pragma (parser); |
| 14866 | if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 14867 | c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); |
| 14868 | else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
| 14869 | c_parser_error (parser, "expected %<(%> or end of line" ); |
| 14870 | c_parser_skip_to_pragma_eol (parser); |
| 14871 | |
| 14872 | c_finish_omp_flush (loc); |
| 14873 | } |
| 14874 | |
| 14875 | /* Parse the restricted form of loop statements allowed by OpenACC and OpenMP. |
| 14876 | The real trick here is to determine the loop control variable early |
| 14877 | so that we can push a new decl if necessary to make it private. |
| 14878 | LOC is the location of the "acc" or "omp" in "#pragma acc" or "#pragma omp", |
| 14879 | respectively. */ |
| 14880 | |
| 14881 | static tree |
| 14882 | c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code, |
| 14883 | tree clauses, tree *cclauses, bool *if_p) |
| 14884 | { |
| 14885 | tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl; |
| 14886 | tree declv, condv, incrv, initv, ret = NULL_TREE; |
| 14887 | tree pre_body = NULL_TREE, this_pre_body; |
| 14888 | tree ordered_cl = NULL_TREE; |
| 14889 | bool fail = false, open_brace_parsed = false; |
| 14890 | int i, collapse = 1, ordered = 0, count, nbraces = 0; |
| 14891 | location_t for_loc; |
| 14892 | bool tiling = false; |
| 14893 | vec<tree, va_gc> *for_block = make_tree_vector (); |
| 14894 | |
| 14895 | for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl)) |
| 14896 | if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE) |
| 14897 | collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (cl)); |
| 14898 | else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_TILE) |
| 14899 | { |
| 14900 | tiling = true; |
| 14901 | collapse = list_length (OMP_CLAUSE_TILE_LIST (cl)); |
| 14902 | } |
| 14903 | else if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_ORDERED |
| 14904 | && OMP_CLAUSE_ORDERED_EXPR (cl)) |
| 14905 | { |
| 14906 | ordered_cl = cl; |
| 14907 | ordered = tree_to_shwi (OMP_CLAUSE_ORDERED_EXPR (cl)); |
| 14908 | } |
| 14909 | |
| 14910 | if (ordered && ordered < collapse) |
| 14911 | { |
| 14912 | error_at (OMP_CLAUSE_LOCATION (ordered_cl), |
| 14913 | "%<ordered%> clause parameter is less than %<collapse%>" ); |
| 14914 | OMP_CLAUSE_ORDERED_EXPR (ordered_cl) |
| 14915 | = build_int_cst (NULL_TREE, collapse); |
| 14916 | ordered = collapse; |
| 14917 | } |
| 14918 | if (ordered) |
| 14919 | { |
| 14920 | for (tree *pc = &clauses; *pc; ) |
| 14921 | if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_LINEAR) |
| 14922 | { |
| 14923 | error_at (OMP_CLAUSE_LOCATION (*pc), |
| 14924 | "%<linear%> clause may not be specified together " |
| 14925 | "with %<ordered%> clause with a parameter" ); |
| 14926 | *pc = OMP_CLAUSE_CHAIN (*pc); |
| 14927 | } |
| 14928 | else |
| 14929 | pc = &OMP_CLAUSE_CHAIN (*pc); |
| 14930 | } |
| 14931 | |
| 14932 | gcc_assert (tiling || (collapse >= 1 && ordered >= 0)); |
| 14933 | count = ordered ? ordered : collapse; |
| 14934 | |
| 14935 | declv = make_tree_vec (count); |
| 14936 | initv = make_tree_vec (count); |
| 14937 | condv = make_tree_vec (count); |
| 14938 | incrv = make_tree_vec (count); |
| 14939 | |
| 14940 | if (code != CILK_FOR |
| 14941 | && !c_parser_next_token_is_keyword (parser, RID_FOR)) |
| 14942 | { |
| 14943 | c_parser_error (parser, "for statement expected" ); |
| 14944 | return NULL; |
| 14945 | } |
| 14946 | if (code == CILK_FOR |
| 14947 | && !c_parser_next_token_is_keyword (parser, RID_CILK_FOR)) |
| 14948 | { |
| 14949 | c_parser_error (parser, "_Cilk_for statement expected" ); |
| 14950 | return NULL; |
| 14951 | } |
| 14952 | for_loc = c_parser_peek_token (parser)->location; |
| 14953 | c_parser_consume_token (parser); |
| 14954 | |
| 14955 | for (i = 0; i < count; i++) |
| 14956 | { |
| 14957 | int bracecount = 0; |
| 14958 | |
| 14959 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 14960 | goto pop_scopes; |
| 14961 | |
| 14962 | /* Parse the initialization declaration or expression. */ |
| 14963 | if (c_parser_next_tokens_start_declaration (parser)) |
| 14964 | { |
| 14965 | if (i > 0) |
| 14966 | vec_safe_push (for_block, c_begin_compound_stmt (true)); |
| 14967 | this_pre_body = push_stmt_list (); |
| 14968 | c_parser_declaration_or_fndef (parser, true, true, true, true, true, |
| 14969 | NULL, vNULL); |
| 14970 | if (this_pre_body) |
| 14971 | { |
| 14972 | this_pre_body = pop_stmt_list (this_pre_body); |
| 14973 | if (pre_body) |
| 14974 | { |
| 14975 | tree t = pre_body; |
| 14976 | pre_body = push_stmt_list (); |
| 14977 | add_stmt (t); |
| 14978 | add_stmt (this_pre_body); |
| 14979 | pre_body = pop_stmt_list (pre_body); |
| 14980 | } |
| 14981 | else |
| 14982 | pre_body = this_pre_body; |
| 14983 | } |
| 14984 | decl = check_for_loop_decls (for_loc, flag_isoc99); |
| 14985 | if (decl == NULL) |
| 14986 | goto error_init; |
| 14987 | if (DECL_INITIAL (decl) == error_mark_node) |
| 14988 | decl = error_mark_node; |
| 14989 | init = decl; |
| 14990 | } |
| 14991 | else if (c_parser_next_token_is (parser, CPP_NAME) |
| 14992 | && c_parser_peek_2nd_token (parser)->type == CPP_EQ) |
| 14993 | { |
| 14994 | struct c_expr decl_exp; |
| 14995 | struct c_expr init_exp; |
| 14996 | location_t init_loc; |
| 14997 | |
| 14998 | decl_exp = c_parser_postfix_expression (parser); |
| 14999 | decl = decl_exp.value; |
| 15000 | |
| 15001 | c_parser_require (parser, CPP_EQ, "expected %<=%>" ); |
| 15002 | |
| 15003 | init_loc = c_parser_peek_token (parser)->location; |
| 15004 | init_exp = c_parser_expr_no_commas (parser, NULL); |
| 15005 | init_exp = default_function_array_read_conversion (init_loc, |
| 15006 | init_exp); |
| 15007 | init = build_modify_expr (init_loc, decl, decl_exp.original_type, |
| 15008 | NOP_EXPR, init_loc, init_exp.value, |
| 15009 | init_exp.original_type); |
| 15010 | init = c_process_expr_stmt (init_loc, init); |
| 15011 | |
| 15012 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>" ); |
| 15013 | } |
| 15014 | else |
| 15015 | { |
| 15016 | error_init: |
| 15017 | c_parser_error (parser, |
| 15018 | "expected iteration declaration or initialization" ); |
| 15019 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, |
| 15020 | "expected %<)%>" ); |
| 15021 | fail = true; |
| 15022 | goto parse_next; |
| 15023 | } |
| 15024 | |
| 15025 | /* Parse the loop condition. */ |
| 15026 | cond = NULL_TREE; |
| 15027 | if (c_parser_next_token_is_not (parser, CPP_SEMICOLON)) |
| 15028 | { |
| 15029 | location_t cond_loc = c_parser_peek_token (parser)->location; |
| 15030 | struct c_expr cond_expr |
| 15031 | = c_parser_binary_expression (parser, NULL, NULL_TREE); |
| 15032 | |
| 15033 | cond = cond_expr.value; |
| 15034 | cond = c_objc_common_truthvalue_conversion (cond_loc, cond); |
| 15035 | if (COMPARISON_CLASS_P (cond)) |
| 15036 | { |
| 15037 | tree op0 = TREE_OPERAND (cond, 0), op1 = TREE_OPERAND (cond, 1); |
| 15038 | op0 = c_fully_fold (op0, false, NULL); |
| 15039 | op1 = c_fully_fold (op1, false, NULL); |
| 15040 | TREE_OPERAND (cond, 0) = op0; |
| 15041 | TREE_OPERAND (cond, 1) = op1; |
| 15042 | } |
| 15043 | switch (cond_expr.original_code) |
| 15044 | { |
| 15045 | case GT_EXPR: |
| 15046 | case GE_EXPR: |
| 15047 | case LT_EXPR: |
| 15048 | case LE_EXPR: |
| 15049 | break; |
| 15050 | case NE_EXPR: |
| 15051 | if (code == CILK_SIMD || code == CILK_FOR) |
| 15052 | break; |
| 15053 | /* FALLTHRU. */ |
| 15054 | default: |
| 15055 | /* Can't be cond = error_mark_node, because we want to preserve |
| 15056 | the location until c_finish_omp_for. */ |
| 15057 | cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node); |
| 15058 | break; |
| 15059 | } |
| 15060 | protected_set_expr_location (cond, cond_loc); |
| 15061 | } |
| 15062 | c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>" ); |
| 15063 | |
| 15064 | /* Parse the increment expression. */ |
| 15065 | incr = NULL_TREE; |
| 15066 | if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)) |
| 15067 | { |
| 15068 | location_t incr_loc = c_parser_peek_token (parser)->location; |
| 15069 | |
| 15070 | incr = c_process_expr_stmt (incr_loc, |
| 15071 | c_parser_expression (parser).value); |
| 15072 | } |
| 15073 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 15074 | |
| 15075 | if (decl == NULL || decl == error_mark_node || init == error_mark_node) |
| 15076 | fail = true; |
| 15077 | else |
| 15078 | { |
| 15079 | TREE_VEC_ELT (declv, i) = decl; |
| 15080 | TREE_VEC_ELT (initv, i) = init; |
| 15081 | TREE_VEC_ELT (condv, i) = cond; |
| 15082 | TREE_VEC_ELT (incrv, i) = incr; |
| 15083 | } |
| 15084 | |
| 15085 | parse_next: |
| 15086 | if (i == count - 1) |
| 15087 | break; |
| 15088 | |
| 15089 | /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed |
| 15090 | in between the collapsed for loops to be still considered perfectly |
| 15091 | nested. Hopefully the final version clarifies this. |
| 15092 | For now handle (multiple) {'s and empty statements. */ |
| 15093 | do |
| 15094 | { |
| 15095 | if (c_parser_next_token_is_keyword (parser, RID_FOR)) |
| 15096 | { |
| 15097 | c_parser_consume_token (parser); |
| 15098 | break; |
| 15099 | } |
| 15100 | else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) |
| 15101 | { |
| 15102 | c_parser_consume_token (parser); |
| 15103 | bracecount++; |
| 15104 | } |
| 15105 | else if (bracecount |
| 15106 | && c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 15107 | c_parser_consume_token (parser); |
| 15108 | else |
| 15109 | { |
| 15110 | c_parser_error (parser, "not enough perfectly nested loops" ); |
| 15111 | if (bracecount) |
| 15112 | { |
| 15113 | open_brace_parsed = true; |
| 15114 | bracecount--; |
| 15115 | } |
| 15116 | fail = true; |
| 15117 | count = 0; |
| 15118 | break; |
| 15119 | } |
| 15120 | } |
| 15121 | while (1); |
| 15122 | |
| 15123 | nbraces += bracecount; |
| 15124 | } |
| 15125 | |
| 15126 | if (nbraces) |
| 15127 | if_p = NULL; |
| 15128 | |
| 15129 | save_break = c_break_label; |
| 15130 | if (code == CILK_SIMD) |
| 15131 | c_break_label = build_int_cst (size_type_node, 2); |
| 15132 | else |
| 15133 | c_break_label = size_one_node; |
| 15134 | save_cont = c_cont_label; |
| 15135 | c_cont_label = NULL_TREE; |
| 15136 | body = push_stmt_list (); |
| 15137 | |
| 15138 | if (open_brace_parsed) |
| 15139 | { |
| 15140 | location_t here = c_parser_peek_token (parser)->location; |
| 15141 | stmt = c_begin_compound_stmt (true); |
| 15142 | c_parser_compound_statement_nostart (parser); |
| 15143 | add_stmt (c_end_compound_stmt (here, stmt, true)); |
| 15144 | } |
| 15145 | else |
| 15146 | add_stmt (c_parser_c99_block_statement (parser, if_p)); |
| 15147 | if (c_cont_label) |
| 15148 | { |
| 15149 | tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label); |
| 15150 | SET_EXPR_LOCATION (t, loc); |
| 15151 | add_stmt (t); |
| 15152 | } |
| 15153 | |
| 15154 | body = pop_stmt_list (body); |
| 15155 | c_break_label = save_break; |
| 15156 | c_cont_label = save_cont; |
| 15157 | |
| 15158 | while (nbraces) |
| 15159 | { |
| 15160 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 15161 | { |
| 15162 | c_parser_consume_token (parser); |
| 15163 | nbraces--; |
| 15164 | } |
| 15165 | else if (c_parser_next_token_is (parser, CPP_SEMICOLON)) |
| 15166 | c_parser_consume_token (parser); |
| 15167 | else |
| 15168 | { |
| 15169 | c_parser_error (parser, "collapsed loops not perfectly nested" ); |
| 15170 | while (nbraces) |
| 15171 | { |
| 15172 | location_t here = c_parser_peek_token (parser)->location; |
| 15173 | stmt = c_begin_compound_stmt (true); |
| 15174 | add_stmt (body); |
| 15175 | c_parser_compound_statement_nostart (parser); |
| 15176 | body = c_end_compound_stmt (here, stmt, true); |
| 15177 | nbraces--; |
| 15178 | } |
| 15179 | goto pop_scopes; |
| 15180 | } |
| 15181 | } |
| 15182 | |
| 15183 | /* Only bother calling c_finish_omp_for if we haven't already generated |
| 15184 | an error from the initialization parsing. */ |
| 15185 | if (!fail) |
| 15186 | { |
| 15187 | stmt = c_finish_omp_for (loc, code, declv, NULL, initv, condv, |
| 15188 | incrv, body, pre_body); |
| 15189 | |
| 15190 | /* Check for iterators appearing in lb, b or incr expressions. */ |
| 15191 | if (stmt && !c_omp_check_loop_iv (stmt, declv, NULL)) |
| 15192 | stmt = NULL_TREE; |
| 15193 | |
| 15194 | if (stmt) |
| 15195 | { |
| 15196 | add_stmt (stmt); |
| 15197 | |
| 15198 | if (cclauses != NULL |
| 15199 | && cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL] != NULL) |
| 15200 | { |
| 15201 | tree *c; |
| 15202 | for (c = &cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; *c ; ) |
| 15203 | if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE |
| 15204 | && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE) |
| 15205 | c = &OMP_CLAUSE_CHAIN (*c); |
| 15206 | else |
| 15207 | { |
| 15208 | for (i = 0; i < count; i++) |
| 15209 | if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c)) |
| 15210 | break; |
| 15211 | if (i == count) |
| 15212 | c = &OMP_CLAUSE_CHAIN (*c); |
| 15213 | else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE) |
| 15214 | { |
| 15215 | error_at (loc, |
| 15216 | "iteration variable %qD should not be firstprivate" , |
| 15217 | OMP_CLAUSE_DECL (*c)); |
| 15218 | *c = OMP_CLAUSE_CHAIN (*c); |
| 15219 | } |
| 15220 | else |
| 15221 | { |
| 15222 | /* Move lastprivate (decl) clause to OMP_FOR_CLAUSES. */ |
| 15223 | tree l = *c; |
| 15224 | *c = OMP_CLAUSE_CHAIN (*c); |
| 15225 | if (code == OMP_SIMD) |
| 15226 | { |
| 15227 | OMP_CLAUSE_CHAIN (l) |
| 15228 | = cclauses[C_OMP_CLAUSE_SPLIT_FOR]; |
| 15229 | cclauses[C_OMP_CLAUSE_SPLIT_FOR] = l; |
| 15230 | } |
| 15231 | else |
| 15232 | { |
| 15233 | OMP_CLAUSE_CHAIN (l) = clauses; |
| 15234 | clauses = l; |
| 15235 | } |
| 15236 | } |
| 15237 | } |
| 15238 | } |
| 15239 | OMP_FOR_CLAUSES (stmt) = clauses; |
| 15240 | } |
| 15241 | ret = stmt; |
| 15242 | } |
| 15243 | pop_scopes: |
| 15244 | while (!for_block->is_empty ()) |
| 15245 | { |
| 15246 | /* FIXME diagnostics: LOC below should be the actual location of |
| 15247 | this particular for block. We need to build a list of |
| 15248 | locations to go along with FOR_BLOCK. */ |
| 15249 | stmt = c_end_compound_stmt (loc, for_block->pop (), true); |
| 15250 | add_stmt (stmt); |
| 15251 | } |
| 15252 | release_tree_vector (for_block); |
| 15253 | return ret; |
| 15254 | } |
| 15255 | |
| 15256 | /* Helper function for OpenMP parsing, split clauses and call |
| 15257 | finish_omp_clauses on each of the set of clauses afterwards. */ |
| 15258 | |
| 15259 | static void |
| 15260 | omp_split_clauses (location_t loc, enum tree_code code, |
| 15261 | omp_clause_mask mask, tree clauses, tree *cclauses) |
| 15262 | { |
| 15263 | int i; |
| 15264 | c_omp_split_clauses (loc, code, mask, clauses, cclauses); |
| 15265 | for (i = 0; i < C_OMP_CLAUSE_SPLIT_COUNT; i++) |
| 15266 | if (cclauses[i]) |
| 15267 | cclauses[i] = c_finish_omp_clauses (cclauses[i], C_ORT_OMP); |
| 15268 | } |
| 15269 | |
| 15270 | /* OpenMP 4.0: |
| 15271 | #pragma omp simd simd-clause[optseq] new-line |
| 15272 | for-loop |
| 15273 | |
| 15274 | LOC is the location of the #pragma token. |
| 15275 | */ |
| 15276 | |
| 15277 | #define OMP_SIMD_CLAUSE_MASK \ |
| 15278 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SAFELEN) \ |
| 15279 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \ |
| 15280 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \ |
| 15281 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \ |
| 15282 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 15283 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ |
| 15284 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ |
| 15285 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)) |
| 15286 | |
| 15287 | static tree |
| 15288 | c_parser_omp_simd (location_t loc, c_parser *parser, |
| 15289 | char *p_name, omp_clause_mask mask, tree *cclauses, |
| 15290 | bool *if_p) |
| 15291 | { |
| 15292 | tree block, clauses, ret; |
| 15293 | |
| 15294 | strcat (p_name, " simd" ); |
| 15295 | mask |= OMP_SIMD_CLAUSE_MASK; |
| 15296 | |
| 15297 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
| 15298 | if (cclauses) |
| 15299 | { |
| 15300 | omp_split_clauses (loc, OMP_SIMD, mask, clauses, cclauses); |
| 15301 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_SIMD]; |
| 15302 | tree c = omp_find_clause (cclauses[C_OMP_CLAUSE_SPLIT_FOR], |
| 15303 | OMP_CLAUSE_ORDERED); |
| 15304 | if (c && OMP_CLAUSE_ORDERED_EXPR (c)) |
| 15305 | { |
| 15306 | error_at (OMP_CLAUSE_LOCATION (c), |
| 15307 | "%<ordered%> clause with parameter may not be specified " |
| 15308 | "on %qs construct" , p_name); |
| 15309 | OMP_CLAUSE_ORDERED_EXPR (c) = NULL_TREE; |
| 15310 | } |
| 15311 | } |
| 15312 | |
| 15313 | block = c_begin_compound_stmt (true); |
| 15314 | ret = c_parser_omp_for_loop (loc, parser, OMP_SIMD, clauses, cclauses, if_p); |
| 15315 | block = c_end_compound_stmt (loc, block, true); |
| 15316 | add_stmt (block); |
| 15317 | |
| 15318 | return ret; |
| 15319 | } |
| 15320 | |
| 15321 | /* OpenMP 2.5: |
| 15322 | #pragma omp for for-clause[optseq] new-line |
| 15323 | for-loop |
| 15324 | |
| 15325 | OpenMP 4.0: |
| 15326 | #pragma omp for simd for-simd-clause[optseq] new-line |
| 15327 | for-loop |
| 15328 | |
| 15329 | LOC is the location of the #pragma token. |
| 15330 | */ |
| 15331 | |
| 15332 | #define OMP_FOR_CLAUSE_MASK \ |
| 15333 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 15334 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
| 15335 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ |
| 15336 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \ |
| 15337 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ |
| 15338 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED) \ |
| 15339 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SCHEDULE) \ |
| 15340 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \ |
| 15341 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) |
| 15342 | |
| 15343 | static tree |
| 15344 | c_parser_omp_for (location_t loc, c_parser *parser, |
| 15345 | char *p_name, omp_clause_mask mask, tree *cclauses, |
| 15346 | bool *if_p) |
| 15347 | { |
| 15348 | tree block, clauses, ret; |
| 15349 | |
| 15350 | strcat (p_name, " for" ); |
| 15351 | mask |= OMP_FOR_CLAUSE_MASK; |
| 15352 | /* parallel for{, simd} disallows nowait clause, but for |
| 15353 | target {teams distribute ,}parallel for{, simd} it should be accepted. */ |
| 15354 | if (cclauses && (mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) == 0) |
| 15355 | mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT); |
| 15356 | /* Composite distribute parallel for{, simd} disallows ordered clause. */ |
| 15357 | if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0) |
| 15358 | mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ORDERED); |
| 15359 | |
| 15360 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 15361 | { |
| 15362 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 15363 | |
| 15364 | if (strcmp (p, "simd" ) == 0) |
| 15365 | { |
| 15366 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 15367 | if (cclauses == NULL) |
| 15368 | cclauses = cclauses_buf; |
| 15369 | |
| 15370 | c_parser_consume_token (parser); |
| 15371 | if (!flag_openmp) /* flag_openmp_simd */ |
| 15372 | return c_parser_omp_simd (loc, parser, p_name, mask, cclauses, |
| 15373 | if_p); |
| 15374 | block = c_begin_compound_stmt (true); |
| 15375 | ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses, if_p); |
| 15376 | block = c_end_compound_stmt (loc, block, true); |
| 15377 | if (ret == NULL_TREE) |
| 15378 | return ret; |
| 15379 | ret = make_node (OMP_FOR); |
| 15380 | TREE_TYPE (ret) = void_type_node; |
| 15381 | OMP_FOR_BODY (ret) = block; |
| 15382 | OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_FOR]; |
| 15383 | SET_EXPR_LOCATION (ret, loc); |
| 15384 | add_stmt (ret); |
| 15385 | return ret; |
| 15386 | } |
| 15387 | } |
| 15388 | if (!flag_openmp) /* flag_openmp_simd */ |
| 15389 | { |
| 15390 | c_parser_skip_to_pragma_eol (parser, false); |
| 15391 | return NULL_TREE; |
| 15392 | } |
| 15393 | |
| 15394 | /* Composite distribute parallel for disallows linear clause. */ |
| 15395 | if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0) |
| 15396 | mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR); |
| 15397 | |
| 15398 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
| 15399 | if (cclauses) |
| 15400 | { |
| 15401 | omp_split_clauses (loc, OMP_FOR, mask, clauses, cclauses); |
| 15402 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_FOR]; |
| 15403 | } |
| 15404 | |
| 15405 | block = c_begin_compound_stmt (true); |
| 15406 | ret = c_parser_omp_for_loop (loc, parser, OMP_FOR, clauses, cclauses, if_p); |
| 15407 | block = c_end_compound_stmt (loc, block, true); |
| 15408 | add_stmt (block); |
| 15409 | |
| 15410 | return ret; |
| 15411 | } |
| 15412 | |
| 15413 | /* OpenMP 2.5: |
| 15414 | # pragma omp master new-line |
| 15415 | structured-block |
| 15416 | |
| 15417 | LOC is the location of the #pragma token. |
| 15418 | */ |
| 15419 | |
| 15420 | static tree |
| 15421 | c_parser_omp_master (location_t loc, c_parser *parser, bool *if_p) |
| 15422 | { |
| 15423 | c_parser_skip_to_pragma_eol (parser); |
| 15424 | return c_finish_omp_master (loc, c_parser_omp_structured_block (parser, |
| 15425 | if_p)); |
| 15426 | } |
| 15427 | |
| 15428 | /* OpenMP 2.5: |
| 15429 | # pragma omp ordered new-line |
| 15430 | structured-block |
| 15431 | |
| 15432 | OpenMP 4.5: |
| 15433 | # pragma omp ordered ordered-clauses new-line |
| 15434 | structured-block |
| 15435 | |
| 15436 | # pragma omp ordered depend-clauses new-line */ |
| 15437 | |
| 15438 | #define OMP_ORDERED_CLAUSE_MASK \ |
| 15439 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREADS) \ |
| 15440 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMD)) |
| 15441 | |
| 15442 | #define OMP_ORDERED_DEPEND_CLAUSE_MASK \ |
| 15443 | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) |
| 15444 | |
| 15445 | static bool |
| 15446 | c_parser_omp_ordered (c_parser *parser, enum pragma_context context, |
| 15447 | bool *if_p) |
| 15448 | { |
| 15449 | location_t loc = c_parser_peek_token (parser)->location; |
| 15450 | c_parser_consume_pragma (parser); |
| 15451 | |
| 15452 | if (context != pragma_stmt && context != pragma_compound) |
| 15453 | { |
| 15454 | c_parser_error (parser, "expected declaration specifiers" ); |
| 15455 | c_parser_skip_to_pragma_eol (parser, false); |
| 15456 | return false; |
| 15457 | } |
| 15458 | |
| 15459 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 15460 | { |
| 15461 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 15462 | |
| 15463 | if (!strcmp ("depend" , p)) |
| 15464 | { |
| 15465 | if (context == pragma_stmt) |
| 15466 | { |
| 15467 | error_at (loc, |
| 15468 | "%<#pragma omp ordered%> with %<depend%> clause may " |
| 15469 | "only be used in compound statements" ); |
| 15470 | c_parser_skip_to_pragma_eol (parser, false); |
| 15471 | return false; |
| 15472 | } |
| 15473 | |
| 15474 | tree clauses |
| 15475 | = c_parser_omp_all_clauses (parser, |
| 15476 | OMP_ORDERED_DEPEND_CLAUSE_MASK, |
| 15477 | "#pragma omp ordered" ); |
| 15478 | c_finish_omp_ordered (loc, clauses, NULL_TREE); |
| 15479 | return false; |
| 15480 | } |
| 15481 | } |
| 15482 | |
| 15483 | tree clauses = c_parser_omp_all_clauses (parser, OMP_ORDERED_CLAUSE_MASK, |
| 15484 | "#pragma omp ordered" ); |
| 15485 | c_finish_omp_ordered (loc, clauses, |
| 15486 | c_parser_omp_structured_block (parser, if_p)); |
| 15487 | return true; |
| 15488 | } |
| 15489 | |
| 15490 | /* OpenMP 2.5: |
| 15491 | |
| 15492 | section-scope: |
| 15493 | { section-sequence } |
| 15494 | |
| 15495 | section-sequence: |
| 15496 | section-directive[opt] structured-block |
| 15497 | section-sequence section-directive structured-block |
| 15498 | |
| 15499 | SECTIONS_LOC is the location of the #pragma omp sections. */ |
| 15500 | |
| 15501 | static tree |
| 15502 | c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser) |
| 15503 | { |
| 15504 | tree stmt, substmt; |
| 15505 | bool error_suppress = false; |
| 15506 | location_t loc; |
| 15507 | |
| 15508 | loc = c_parser_peek_token (parser)->location; |
| 15509 | if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>" )) |
| 15510 | { |
| 15511 | /* Avoid skipping until the end of the block. */ |
| 15512 | parser->error = false; |
| 15513 | return NULL_TREE; |
| 15514 | } |
| 15515 | |
| 15516 | stmt = push_stmt_list (); |
| 15517 | |
| 15518 | if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION) |
| 15519 | { |
| 15520 | substmt = c_parser_omp_structured_block (parser, NULL); |
| 15521 | substmt = build1 (OMP_SECTION, void_type_node, substmt); |
| 15522 | SET_EXPR_LOCATION (substmt, loc); |
| 15523 | add_stmt (substmt); |
| 15524 | } |
| 15525 | |
| 15526 | while (1) |
| 15527 | { |
| 15528 | if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) |
| 15529 | break; |
| 15530 | if (c_parser_next_token_is (parser, CPP_EOF)) |
| 15531 | break; |
| 15532 | |
| 15533 | loc = c_parser_peek_token (parser)->location; |
| 15534 | if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION) |
| 15535 | { |
| 15536 | c_parser_consume_pragma (parser); |
| 15537 | c_parser_skip_to_pragma_eol (parser); |
| 15538 | error_suppress = false; |
| 15539 | } |
| 15540 | else if (!error_suppress) |
| 15541 | { |
| 15542 | error_at (loc, "expected %<#pragma omp section%> or %<}%>" ); |
| 15543 | error_suppress = true; |
| 15544 | } |
| 15545 | |
| 15546 | substmt = c_parser_omp_structured_block (parser, NULL); |
| 15547 | substmt = build1 (OMP_SECTION, void_type_node, substmt); |
| 15548 | SET_EXPR_LOCATION (substmt, loc); |
| 15549 | add_stmt (substmt); |
| 15550 | } |
| 15551 | c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, |
| 15552 | "expected %<#pragma omp section%> or %<}%>" ); |
| 15553 | |
| 15554 | substmt = pop_stmt_list (stmt); |
| 15555 | |
| 15556 | stmt = make_node (OMP_SECTIONS); |
| 15557 | SET_EXPR_LOCATION (stmt, sections_loc); |
| 15558 | TREE_TYPE (stmt) = void_type_node; |
| 15559 | OMP_SECTIONS_BODY (stmt) = substmt; |
| 15560 | |
| 15561 | return add_stmt (stmt); |
| 15562 | } |
| 15563 | |
| 15564 | /* OpenMP 2.5: |
| 15565 | # pragma omp sections sections-clause[optseq] newline |
| 15566 | sections-scope |
| 15567 | |
| 15568 | LOC is the location of the #pragma token. |
| 15569 | */ |
| 15570 | |
| 15571 | #define OMP_SECTIONS_CLAUSE_MASK \ |
| 15572 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 15573 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
| 15574 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ |
| 15575 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ |
| 15576 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) |
| 15577 | |
| 15578 | static tree |
| 15579 | c_parser_omp_sections (location_t loc, c_parser *parser, |
| 15580 | char *p_name, omp_clause_mask mask, tree *cclauses) |
| 15581 | { |
| 15582 | tree block, clauses, ret; |
| 15583 | |
| 15584 | strcat (p_name, " sections" ); |
| 15585 | mask |= OMP_SECTIONS_CLAUSE_MASK; |
| 15586 | if (cclauses) |
| 15587 | mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT); |
| 15588 | |
| 15589 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
| 15590 | if (cclauses) |
| 15591 | { |
| 15592 | omp_split_clauses (loc, OMP_SECTIONS, mask, clauses, cclauses); |
| 15593 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_SECTIONS]; |
| 15594 | } |
| 15595 | |
| 15596 | block = c_begin_compound_stmt (true); |
| 15597 | ret = c_parser_omp_sections_scope (loc, parser); |
| 15598 | if (ret) |
| 15599 | OMP_SECTIONS_CLAUSES (ret) = clauses; |
| 15600 | block = c_end_compound_stmt (loc, block, true); |
| 15601 | add_stmt (block); |
| 15602 | |
| 15603 | return ret; |
| 15604 | } |
| 15605 | |
| 15606 | /* OpenMP 2.5: |
| 15607 | # pragma omp parallel parallel-clause[optseq] new-line |
| 15608 | structured-block |
| 15609 | # pragma omp parallel for parallel-for-clause[optseq] new-line |
| 15610 | structured-block |
| 15611 | # pragma omp parallel sections parallel-sections-clause[optseq] new-line |
| 15612 | structured-block |
| 15613 | |
| 15614 | OpenMP 4.0: |
| 15615 | # pragma omp parallel for simd parallel-for-simd-clause[optseq] new-line |
| 15616 | structured-block |
| 15617 | |
| 15618 | LOC is the location of the #pragma token. |
| 15619 | */ |
| 15620 | |
| 15621 | #define OMP_PARALLEL_CLAUSE_MASK \ |
| 15622 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
| 15623 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 15624 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
| 15625 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \ |
| 15626 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ |
| 15627 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN) \ |
| 15628 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ |
| 15629 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_THREADS) \ |
| 15630 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PROC_BIND)) |
| 15631 | |
| 15632 | static tree |
| 15633 | c_parser_omp_parallel (location_t loc, c_parser *parser, |
| 15634 | char *p_name, omp_clause_mask mask, tree *cclauses, |
| 15635 | bool *if_p) |
| 15636 | { |
| 15637 | tree stmt, clauses, block; |
| 15638 | |
| 15639 | strcat (p_name, " parallel" ); |
| 15640 | mask |= OMP_PARALLEL_CLAUSE_MASK; |
| 15641 | /* #pragma omp target parallel{, for, for simd} disallow copyin clause. */ |
| 15642 | if ((mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP)) != 0 |
| 15643 | && (mask & (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) == 0) |
| 15644 | mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYIN); |
| 15645 | |
| 15646 | if (c_parser_next_token_is_keyword (parser, RID_FOR)) |
| 15647 | { |
| 15648 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 15649 | if (cclauses == NULL) |
| 15650 | cclauses = cclauses_buf; |
| 15651 | |
| 15652 | c_parser_consume_token (parser); |
| 15653 | if (!flag_openmp) /* flag_openmp_simd */ |
| 15654 | return c_parser_omp_for (loc, parser, p_name, mask, cclauses, if_p); |
| 15655 | block = c_begin_omp_parallel (); |
| 15656 | tree ret = c_parser_omp_for (loc, parser, p_name, mask, cclauses, if_p); |
| 15657 | stmt |
| 15658 | = c_finish_omp_parallel (loc, cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL], |
| 15659 | block); |
| 15660 | if (ret == NULL_TREE) |
| 15661 | return ret; |
| 15662 | OMP_PARALLEL_COMBINED (stmt) = 1; |
| 15663 | return stmt; |
| 15664 | } |
| 15665 | /* When combined with distribute, parallel has to be followed by for. |
| 15666 | #pragma omp target parallel is allowed though. */ |
| 15667 | else if (cclauses |
| 15668 | && (mask & (OMP_CLAUSE_MASK_1 |
| 15669 | << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)) != 0) |
| 15670 | { |
| 15671 | error_at (loc, "expected %<for%> after %qs" , p_name); |
| 15672 | c_parser_skip_to_pragma_eol (parser); |
| 15673 | return NULL_TREE; |
| 15674 | } |
| 15675 | else if (!flag_openmp) /* flag_openmp_simd */ |
| 15676 | { |
| 15677 | c_parser_skip_to_pragma_eol (parser, false); |
| 15678 | return NULL_TREE; |
| 15679 | } |
| 15680 | else if (cclauses == NULL && c_parser_next_token_is (parser, CPP_NAME)) |
| 15681 | { |
| 15682 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 15683 | if (strcmp (p, "sections" ) == 0) |
| 15684 | { |
| 15685 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 15686 | if (cclauses == NULL) |
| 15687 | cclauses = cclauses_buf; |
| 15688 | |
| 15689 | c_parser_consume_token (parser); |
| 15690 | block = c_begin_omp_parallel (); |
| 15691 | c_parser_omp_sections (loc, parser, p_name, mask, cclauses); |
| 15692 | stmt = c_finish_omp_parallel (loc, |
| 15693 | cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL], |
| 15694 | block); |
| 15695 | OMP_PARALLEL_COMBINED (stmt) = 1; |
| 15696 | return stmt; |
| 15697 | } |
| 15698 | } |
| 15699 | |
| 15700 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
| 15701 | if (cclauses) |
| 15702 | { |
| 15703 | omp_split_clauses (loc, OMP_PARALLEL, mask, clauses, cclauses); |
| 15704 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_PARALLEL]; |
| 15705 | } |
| 15706 | |
| 15707 | block = c_begin_omp_parallel (); |
| 15708 | c_parser_statement (parser, if_p); |
| 15709 | stmt = c_finish_omp_parallel (loc, clauses, block); |
| 15710 | |
| 15711 | return stmt; |
| 15712 | } |
| 15713 | |
| 15714 | /* OpenMP 2.5: |
| 15715 | # pragma omp single single-clause[optseq] new-line |
| 15716 | structured-block |
| 15717 | |
| 15718 | LOC is the location of the #pragma. |
| 15719 | */ |
| 15720 | |
| 15721 | #define OMP_SINGLE_CLAUSE_MASK \ |
| 15722 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 15723 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
| 15724 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \ |
| 15725 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) |
| 15726 | |
| 15727 | static tree |
| 15728 | c_parser_omp_single (location_t loc, c_parser *parser, bool *if_p) |
| 15729 | { |
| 15730 | tree stmt = make_node (OMP_SINGLE); |
| 15731 | SET_EXPR_LOCATION (stmt, loc); |
| 15732 | TREE_TYPE (stmt) = void_type_node; |
| 15733 | |
| 15734 | OMP_SINGLE_CLAUSES (stmt) |
| 15735 | = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK, |
| 15736 | "#pragma omp single" ); |
| 15737 | OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser, if_p); |
| 15738 | |
| 15739 | return add_stmt (stmt); |
| 15740 | } |
| 15741 | |
| 15742 | /* OpenMP 3.0: |
| 15743 | # pragma omp task task-clause[optseq] new-line |
| 15744 | |
| 15745 | LOC is the location of the #pragma. |
| 15746 | */ |
| 15747 | |
| 15748 | #define OMP_TASK_CLAUSE_MASK \ |
| 15749 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
| 15750 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \ |
| 15751 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \ |
| 15752 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 15753 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
| 15754 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ |
| 15755 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \ |
| 15756 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \ |
| 15757 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ |
| 15758 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY)) |
| 15759 | |
| 15760 | static tree |
| 15761 | c_parser_omp_task (location_t loc, c_parser *parser, bool *if_p) |
| 15762 | { |
| 15763 | tree clauses, block; |
| 15764 | |
| 15765 | clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK, |
| 15766 | "#pragma omp task" ); |
| 15767 | |
| 15768 | block = c_begin_omp_task (); |
| 15769 | c_parser_statement (parser, if_p); |
| 15770 | return c_finish_omp_task (loc, clauses, block); |
| 15771 | } |
| 15772 | |
| 15773 | /* OpenMP 3.0: |
| 15774 | # pragma omp taskwait new-line |
| 15775 | */ |
| 15776 | |
| 15777 | static void |
| 15778 | c_parser_omp_taskwait (c_parser *parser) |
| 15779 | { |
| 15780 | location_t loc = c_parser_peek_token (parser)->location; |
| 15781 | c_parser_consume_pragma (parser); |
| 15782 | c_parser_skip_to_pragma_eol (parser); |
| 15783 | |
| 15784 | c_finish_omp_taskwait (loc); |
| 15785 | } |
| 15786 | |
| 15787 | /* OpenMP 3.1: |
| 15788 | # pragma omp taskyield new-line |
| 15789 | */ |
| 15790 | |
| 15791 | static void |
| 15792 | c_parser_omp_taskyield (c_parser *parser) |
| 15793 | { |
| 15794 | location_t loc = c_parser_peek_token (parser)->location; |
| 15795 | c_parser_consume_pragma (parser); |
| 15796 | c_parser_skip_to_pragma_eol (parser); |
| 15797 | |
| 15798 | c_finish_omp_taskyield (loc); |
| 15799 | } |
| 15800 | |
| 15801 | /* OpenMP 4.0: |
| 15802 | # pragma omp taskgroup new-line |
| 15803 | */ |
| 15804 | |
| 15805 | static tree |
| 15806 | c_parser_omp_taskgroup (c_parser *parser, bool *if_p) |
| 15807 | { |
| 15808 | location_t loc = c_parser_peek_token (parser)->location; |
| 15809 | c_parser_skip_to_pragma_eol (parser); |
| 15810 | return c_finish_omp_taskgroup (loc, c_parser_omp_structured_block (parser, |
| 15811 | if_p)); |
| 15812 | } |
| 15813 | |
| 15814 | /* OpenMP 4.0: |
| 15815 | # pragma omp cancel cancel-clause[optseq] new-line |
| 15816 | |
| 15817 | LOC is the location of the #pragma. |
| 15818 | */ |
| 15819 | |
| 15820 | #define OMP_CANCEL_CLAUSE_MASK \ |
| 15821 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \ |
| 15822 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \ |
| 15823 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \ |
| 15824 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP) \ |
| 15825 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF)) |
| 15826 | |
| 15827 | static void |
| 15828 | c_parser_omp_cancel (c_parser *parser) |
| 15829 | { |
| 15830 | location_t loc = c_parser_peek_token (parser)->location; |
| 15831 | |
| 15832 | c_parser_consume_pragma (parser); |
| 15833 | tree clauses = c_parser_omp_all_clauses (parser, OMP_CANCEL_CLAUSE_MASK, |
| 15834 | "#pragma omp cancel" ); |
| 15835 | |
| 15836 | c_finish_omp_cancel (loc, clauses); |
| 15837 | } |
| 15838 | |
| 15839 | /* OpenMP 4.0: |
| 15840 | # pragma omp cancellation point cancelpt-clause[optseq] new-line |
| 15841 | |
| 15842 | LOC is the location of the #pragma. |
| 15843 | */ |
| 15844 | |
| 15845 | #define OMP_CANCELLATION_POINT_CLAUSE_MASK \ |
| 15846 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PARALLEL) \ |
| 15847 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FOR) \ |
| 15848 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SECTIONS) \ |
| 15849 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TASKGROUP)) |
| 15850 | |
| 15851 | static void |
| 15852 | c_parser_omp_cancellation_point (c_parser *parser, enum pragma_context context) |
| 15853 | { |
| 15854 | location_t loc = c_parser_peek_token (parser)->location; |
| 15855 | tree clauses; |
| 15856 | bool point_seen = false; |
| 15857 | |
| 15858 | c_parser_consume_pragma (parser); |
| 15859 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 15860 | { |
| 15861 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 15862 | if (strcmp (p, "point" ) == 0) |
| 15863 | { |
| 15864 | c_parser_consume_token (parser); |
| 15865 | point_seen = true; |
| 15866 | } |
| 15867 | } |
| 15868 | if (!point_seen) |
| 15869 | { |
| 15870 | c_parser_error (parser, "expected %<point%>" ); |
| 15871 | c_parser_skip_to_pragma_eol (parser); |
| 15872 | return; |
| 15873 | } |
| 15874 | |
| 15875 | if (context != pragma_compound) |
| 15876 | { |
| 15877 | if (context == pragma_stmt) |
| 15878 | error_at (loc, |
| 15879 | "%<#pragma %s%> may only be used in compound statements" , |
| 15880 | "omp cancellation point" ); |
| 15881 | else |
| 15882 | c_parser_error (parser, "expected declaration specifiers" ); |
| 15883 | c_parser_skip_to_pragma_eol (parser, false); |
| 15884 | return; |
| 15885 | } |
| 15886 | |
| 15887 | clauses |
| 15888 | = c_parser_omp_all_clauses (parser, OMP_CANCELLATION_POINT_CLAUSE_MASK, |
| 15889 | "#pragma omp cancellation point" ); |
| 15890 | |
| 15891 | c_finish_omp_cancellation_point (loc, clauses); |
| 15892 | } |
| 15893 | |
| 15894 | /* OpenMP 4.0: |
| 15895 | #pragma omp distribute distribute-clause[optseq] new-line |
| 15896 | for-loop */ |
| 15897 | |
| 15898 | #define OMP_DISTRIBUTE_CLAUSE_MASK \ |
| 15899 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 15900 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
| 15901 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ |
| 15902 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DIST_SCHEDULE)\ |
| 15903 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE)) |
| 15904 | |
| 15905 | static tree |
| 15906 | c_parser_omp_distribute (location_t loc, c_parser *parser, |
| 15907 | char *p_name, omp_clause_mask mask, tree *cclauses, |
| 15908 | bool *if_p) |
| 15909 | { |
| 15910 | tree clauses, block, ret; |
| 15911 | |
| 15912 | strcat (p_name, " distribute" ); |
| 15913 | mask |= OMP_DISTRIBUTE_CLAUSE_MASK; |
| 15914 | |
| 15915 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 15916 | { |
| 15917 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 15918 | bool simd = false; |
| 15919 | bool parallel = false; |
| 15920 | |
| 15921 | if (strcmp (p, "simd" ) == 0) |
| 15922 | simd = true; |
| 15923 | else |
| 15924 | parallel = strcmp (p, "parallel" ) == 0; |
| 15925 | if (parallel || simd) |
| 15926 | { |
| 15927 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 15928 | if (cclauses == NULL) |
| 15929 | cclauses = cclauses_buf; |
| 15930 | c_parser_consume_token (parser); |
| 15931 | if (!flag_openmp) /* flag_openmp_simd */ |
| 15932 | { |
| 15933 | if (simd) |
| 15934 | return c_parser_omp_simd (loc, parser, p_name, mask, cclauses, |
| 15935 | if_p); |
| 15936 | else |
| 15937 | return c_parser_omp_parallel (loc, parser, p_name, mask, |
| 15938 | cclauses, if_p); |
| 15939 | } |
| 15940 | block = c_begin_compound_stmt (true); |
| 15941 | if (simd) |
| 15942 | ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses, |
| 15943 | if_p); |
| 15944 | else |
| 15945 | ret = c_parser_omp_parallel (loc, parser, p_name, mask, cclauses, |
| 15946 | if_p); |
| 15947 | block = c_end_compound_stmt (loc, block, true); |
| 15948 | if (ret == NULL) |
| 15949 | return ret; |
| 15950 | ret = make_node (OMP_DISTRIBUTE); |
| 15951 | TREE_TYPE (ret) = void_type_node; |
| 15952 | OMP_FOR_BODY (ret) = block; |
| 15953 | OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE]; |
| 15954 | SET_EXPR_LOCATION (ret, loc); |
| 15955 | add_stmt (ret); |
| 15956 | return ret; |
| 15957 | } |
| 15958 | } |
| 15959 | if (!flag_openmp) /* flag_openmp_simd */ |
| 15960 | { |
| 15961 | c_parser_skip_to_pragma_eol (parser, false); |
| 15962 | return NULL_TREE; |
| 15963 | } |
| 15964 | |
| 15965 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
| 15966 | if (cclauses) |
| 15967 | { |
| 15968 | omp_split_clauses (loc, OMP_DISTRIBUTE, mask, clauses, cclauses); |
| 15969 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_DISTRIBUTE]; |
| 15970 | } |
| 15971 | |
| 15972 | block = c_begin_compound_stmt (true); |
| 15973 | ret = c_parser_omp_for_loop (loc, parser, OMP_DISTRIBUTE, clauses, NULL, |
| 15974 | if_p); |
| 15975 | block = c_end_compound_stmt (loc, block, true); |
| 15976 | add_stmt (block); |
| 15977 | |
| 15978 | return ret; |
| 15979 | } |
| 15980 | |
| 15981 | /* OpenMP 4.0: |
| 15982 | # pragma omp teams teams-clause[optseq] new-line |
| 15983 | structured-block */ |
| 15984 | |
| 15985 | #define OMP_TEAMS_CLAUSE_MASK \ |
| 15986 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 15987 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
| 15988 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ |
| 15989 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION) \ |
| 15990 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TEAMS) \ |
| 15991 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_THREAD_LIMIT) \ |
| 15992 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT)) |
| 15993 | |
| 15994 | static tree |
| 15995 | c_parser_omp_teams (location_t loc, c_parser *parser, |
| 15996 | char *p_name, omp_clause_mask mask, tree *cclauses, |
| 15997 | bool *if_p) |
| 15998 | { |
| 15999 | tree clauses, block, ret; |
| 16000 | |
| 16001 | strcat (p_name, " teams" ); |
| 16002 | mask |= OMP_TEAMS_CLAUSE_MASK; |
| 16003 | |
| 16004 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 16005 | { |
| 16006 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 16007 | if (strcmp (p, "distribute" ) == 0) |
| 16008 | { |
| 16009 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 16010 | if (cclauses == NULL) |
| 16011 | cclauses = cclauses_buf; |
| 16012 | |
| 16013 | c_parser_consume_token (parser); |
| 16014 | if (!flag_openmp) /* flag_openmp_simd */ |
| 16015 | return c_parser_omp_distribute (loc, parser, p_name, mask, |
| 16016 | cclauses, if_p); |
| 16017 | block = c_begin_compound_stmt (true); |
| 16018 | ret = c_parser_omp_distribute (loc, parser, p_name, mask, cclauses, |
| 16019 | if_p); |
| 16020 | block = c_end_compound_stmt (loc, block, true); |
| 16021 | if (ret == NULL) |
| 16022 | return ret; |
| 16023 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS]; |
| 16024 | ret = make_node (OMP_TEAMS); |
| 16025 | TREE_TYPE (ret) = void_type_node; |
| 16026 | OMP_TEAMS_CLAUSES (ret) = clauses; |
| 16027 | OMP_TEAMS_BODY (ret) = block; |
| 16028 | OMP_TEAMS_COMBINED (ret) = 1; |
| 16029 | return add_stmt (ret); |
| 16030 | } |
| 16031 | } |
| 16032 | if (!flag_openmp) /* flag_openmp_simd */ |
| 16033 | { |
| 16034 | c_parser_skip_to_pragma_eol (parser, false); |
| 16035 | return NULL_TREE; |
| 16036 | } |
| 16037 | |
| 16038 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
| 16039 | if (cclauses) |
| 16040 | { |
| 16041 | omp_split_clauses (loc, OMP_TEAMS, mask, clauses, cclauses); |
| 16042 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS]; |
| 16043 | } |
| 16044 | |
| 16045 | tree stmt = make_node (OMP_TEAMS); |
| 16046 | TREE_TYPE (stmt) = void_type_node; |
| 16047 | OMP_TEAMS_CLAUSES (stmt) = clauses; |
| 16048 | OMP_TEAMS_BODY (stmt) = c_parser_omp_structured_block (parser, if_p); |
| 16049 | |
| 16050 | return add_stmt (stmt); |
| 16051 | } |
| 16052 | |
| 16053 | /* OpenMP 4.0: |
| 16054 | # pragma omp target data target-data-clause[optseq] new-line |
| 16055 | structured-block */ |
| 16056 | |
| 16057 | #define OMP_TARGET_DATA_CLAUSE_MASK \ |
| 16058 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ |
| 16059 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ |
| 16060 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
| 16061 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_USE_DEVICE_PTR)) |
| 16062 | |
| 16063 | static tree |
| 16064 | c_parser_omp_target_data (location_t loc, c_parser *parser, bool *if_p) |
| 16065 | { |
| 16066 | tree clauses |
| 16067 | = c_parser_omp_all_clauses (parser, OMP_TARGET_DATA_CLAUSE_MASK, |
| 16068 | "#pragma omp target data" ); |
| 16069 | int map_seen = 0; |
| 16070 | for (tree *pc = &clauses; *pc;) |
| 16071 | { |
| 16072 | if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP) |
| 16073 | switch (OMP_CLAUSE_MAP_KIND (*pc)) |
| 16074 | { |
| 16075 | case GOMP_MAP_TO: |
| 16076 | case GOMP_MAP_ALWAYS_TO: |
| 16077 | case GOMP_MAP_FROM: |
| 16078 | case GOMP_MAP_ALWAYS_FROM: |
| 16079 | case GOMP_MAP_TOFROM: |
| 16080 | case GOMP_MAP_ALWAYS_TOFROM: |
| 16081 | case GOMP_MAP_ALLOC: |
| 16082 | map_seen = 3; |
| 16083 | break; |
| 16084 | case GOMP_MAP_FIRSTPRIVATE_POINTER: |
| 16085 | case GOMP_MAP_ALWAYS_POINTER: |
| 16086 | break; |
| 16087 | default: |
| 16088 | map_seen |= 1; |
| 16089 | error_at (OMP_CLAUSE_LOCATION (*pc), |
| 16090 | "%<#pragma omp target data%> with map-type other " |
| 16091 | "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> " |
| 16092 | "on %<map%> clause" ); |
| 16093 | *pc = OMP_CLAUSE_CHAIN (*pc); |
| 16094 | continue; |
| 16095 | } |
| 16096 | pc = &OMP_CLAUSE_CHAIN (*pc); |
| 16097 | } |
| 16098 | |
| 16099 | if (map_seen != 3) |
| 16100 | { |
| 16101 | if (map_seen == 0) |
| 16102 | error_at (loc, |
| 16103 | "%<#pragma omp target data%> must contain at least " |
| 16104 | "one %<map%> clause" ); |
| 16105 | return NULL_TREE; |
| 16106 | } |
| 16107 | |
| 16108 | tree stmt = make_node (OMP_TARGET_DATA); |
| 16109 | TREE_TYPE (stmt) = void_type_node; |
| 16110 | OMP_TARGET_DATA_CLAUSES (stmt) = clauses; |
| 16111 | keep_next_level (); |
| 16112 | tree block = c_begin_compound_stmt (true); |
| 16113 | add_stmt (c_parser_omp_structured_block (parser, if_p)); |
| 16114 | OMP_TARGET_DATA_BODY (stmt) = c_end_compound_stmt (loc, block, true); |
| 16115 | |
| 16116 | SET_EXPR_LOCATION (stmt, loc); |
| 16117 | return add_stmt (stmt); |
| 16118 | } |
| 16119 | |
| 16120 | /* OpenMP 4.0: |
| 16121 | # pragma omp target update target-update-clause[optseq] new-line */ |
| 16122 | |
| 16123 | #define OMP_TARGET_UPDATE_CLAUSE_MASK \ |
| 16124 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FROM) \ |
| 16125 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \ |
| 16126 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ |
| 16127 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
| 16128 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ |
| 16129 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) |
| 16130 | |
| 16131 | static bool |
| 16132 | c_parser_omp_target_update (location_t loc, c_parser *parser, |
| 16133 | enum pragma_context context) |
| 16134 | { |
| 16135 | if (context == pragma_stmt) |
| 16136 | { |
| 16137 | error_at (loc, "%<#pragma %s%> may only be used in compound statements" , |
| 16138 | "omp target update" ); |
| 16139 | c_parser_skip_to_pragma_eol (parser, false); |
| 16140 | return false; |
| 16141 | } |
| 16142 | |
| 16143 | tree clauses |
| 16144 | = c_parser_omp_all_clauses (parser, OMP_TARGET_UPDATE_CLAUSE_MASK, |
| 16145 | "#pragma omp target update" ); |
| 16146 | if (omp_find_clause (clauses, OMP_CLAUSE_TO) == NULL_TREE |
| 16147 | && omp_find_clause (clauses, OMP_CLAUSE_FROM) == NULL_TREE) |
| 16148 | { |
| 16149 | error_at (loc, |
| 16150 | "%<#pragma omp target update%> must contain at least one " |
| 16151 | "%<from%> or %<to%> clauses" ); |
| 16152 | return false; |
| 16153 | } |
| 16154 | |
| 16155 | tree stmt = make_node (OMP_TARGET_UPDATE); |
| 16156 | TREE_TYPE (stmt) = void_type_node; |
| 16157 | OMP_TARGET_UPDATE_CLAUSES (stmt) = clauses; |
| 16158 | SET_EXPR_LOCATION (stmt, loc); |
| 16159 | add_stmt (stmt); |
| 16160 | return false; |
| 16161 | } |
| 16162 | |
| 16163 | /* OpenMP 4.5: |
| 16164 | # pragma omp target enter data target-data-clause[optseq] new-line */ |
| 16165 | |
| 16166 | #define OMP_TARGET_ENTER_DATA_CLAUSE_MASK \ |
| 16167 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ |
| 16168 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ |
| 16169 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
| 16170 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ |
| 16171 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) |
| 16172 | |
| 16173 | static tree |
| 16174 | c_parser_omp_target_enter_data (location_t loc, c_parser *parser, |
| 16175 | enum pragma_context context) |
| 16176 | { |
| 16177 | bool data_seen = false; |
| 16178 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 16179 | { |
| 16180 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 16181 | if (strcmp (p, "data" ) == 0) |
| 16182 | { |
| 16183 | c_parser_consume_token (parser); |
| 16184 | data_seen = true; |
| 16185 | } |
| 16186 | } |
| 16187 | if (!data_seen) |
| 16188 | { |
| 16189 | c_parser_error (parser, "expected %<data%>" ); |
| 16190 | c_parser_skip_to_pragma_eol (parser); |
| 16191 | return NULL_TREE; |
| 16192 | } |
| 16193 | |
| 16194 | if (context == pragma_stmt) |
| 16195 | { |
| 16196 | error_at (loc, "%<#pragma %s%> may only be used in compound statements" , |
| 16197 | "omp target enter data" ); |
| 16198 | c_parser_skip_to_pragma_eol (parser, false); |
| 16199 | return NULL_TREE; |
| 16200 | } |
| 16201 | |
| 16202 | tree clauses |
| 16203 | = c_parser_omp_all_clauses (parser, OMP_TARGET_ENTER_DATA_CLAUSE_MASK, |
| 16204 | "#pragma omp target enter data" ); |
| 16205 | int map_seen = 0; |
| 16206 | for (tree *pc = &clauses; *pc;) |
| 16207 | { |
| 16208 | if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP) |
| 16209 | switch (OMP_CLAUSE_MAP_KIND (*pc)) |
| 16210 | { |
| 16211 | case GOMP_MAP_TO: |
| 16212 | case GOMP_MAP_ALWAYS_TO: |
| 16213 | case GOMP_MAP_ALLOC: |
| 16214 | map_seen = 3; |
| 16215 | break; |
| 16216 | case GOMP_MAP_FIRSTPRIVATE_POINTER: |
| 16217 | case GOMP_MAP_ALWAYS_POINTER: |
| 16218 | break; |
| 16219 | default: |
| 16220 | map_seen |= 1; |
| 16221 | error_at (OMP_CLAUSE_LOCATION (*pc), |
| 16222 | "%<#pragma omp target enter data%> with map-type other " |
| 16223 | "than %<to%> or %<alloc%> on %<map%> clause" ); |
| 16224 | *pc = OMP_CLAUSE_CHAIN (*pc); |
| 16225 | continue; |
| 16226 | } |
| 16227 | pc = &OMP_CLAUSE_CHAIN (*pc); |
| 16228 | } |
| 16229 | |
| 16230 | if (map_seen != 3) |
| 16231 | { |
| 16232 | if (map_seen == 0) |
| 16233 | error_at (loc, |
| 16234 | "%<#pragma omp target enter data%> must contain at least " |
| 16235 | "one %<map%> clause" ); |
| 16236 | return NULL_TREE; |
| 16237 | } |
| 16238 | |
| 16239 | tree stmt = make_node (OMP_TARGET_ENTER_DATA); |
| 16240 | TREE_TYPE (stmt) = void_type_node; |
| 16241 | OMP_TARGET_ENTER_DATA_CLAUSES (stmt) = clauses; |
| 16242 | SET_EXPR_LOCATION (stmt, loc); |
| 16243 | add_stmt (stmt); |
| 16244 | return stmt; |
| 16245 | } |
| 16246 | |
| 16247 | /* OpenMP 4.5: |
| 16248 | # pragma omp target exit data target-data-clause[optseq] new-line */ |
| 16249 | |
| 16250 | #define OMP_TARGET_EXIT_DATA_CLAUSE_MASK \ |
| 16251 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ |
| 16252 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ |
| 16253 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
| 16254 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ |
| 16255 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT)) |
| 16256 | |
| 16257 | static tree |
| 16258 | c_parser_omp_target_exit_data (location_t loc, c_parser *parser, |
| 16259 | enum pragma_context context) |
| 16260 | { |
| 16261 | bool data_seen = false; |
| 16262 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 16263 | { |
| 16264 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 16265 | if (strcmp (p, "data" ) == 0) |
| 16266 | { |
| 16267 | c_parser_consume_token (parser); |
| 16268 | data_seen = true; |
| 16269 | } |
| 16270 | } |
| 16271 | if (!data_seen) |
| 16272 | { |
| 16273 | c_parser_error (parser, "expected %<data%>" ); |
| 16274 | c_parser_skip_to_pragma_eol (parser); |
| 16275 | return NULL_TREE; |
| 16276 | } |
| 16277 | |
| 16278 | if (context == pragma_stmt) |
| 16279 | { |
| 16280 | error_at (loc, "%<#pragma %s%> may only be used in compound statements" , |
| 16281 | "omp target exit data" ); |
| 16282 | c_parser_skip_to_pragma_eol (parser, false); |
| 16283 | return NULL_TREE; |
| 16284 | } |
| 16285 | |
| 16286 | tree clauses |
| 16287 | = c_parser_omp_all_clauses (parser, OMP_TARGET_EXIT_DATA_CLAUSE_MASK, |
| 16288 | "#pragma omp target exit data" ); |
| 16289 | |
| 16290 | int map_seen = 0; |
| 16291 | for (tree *pc = &clauses; *pc;) |
| 16292 | { |
| 16293 | if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP) |
| 16294 | switch (OMP_CLAUSE_MAP_KIND (*pc)) |
| 16295 | { |
| 16296 | case GOMP_MAP_FROM: |
| 16297 | case GOMP_MAP_ALWAYS_FROM: |
| 16298 | case GOMP_MAP_RELEASE: |
| 16299 | case GOMP_MAP_DELETE: |
| 16300 | map_seen = 3; |
| 16301 | break; |
| 16302 | case GOMP_MAP_FIRSTPRIVATE_POINTER: |
| 16303 | case GOMP_MAP_ALWAYS_POINTER: |
| 16304 | break; |
| 16305 | default: |
| 16306 | map_seen |= 1; |
| 16307 | error_at (OMP_CLAUSE_LOCATION (*pc), |
| 16308 | "%<#pragma omp target exit data%> with map-type other " |
| 16309 | "than %<from%>, %<release%> or %<delete%> on %<map%>" |
| 16310 | " clause" ); |
| 16311 | *pc = OMP_CLAUSE_CHAIN (*pc); |
| 16312 | continue; |
| 16313 | } |
| 16314 | pc = &OMP_CLAUSE_CHAIN (*pc); |
| 16315 | } |
| 16316 | |
| 16317 | if (map_seen != 3) |
| 16318 | { |
| 16319 | if (map_seen == 0) |
| 16320 | error_at (loc, |
| 16321 | "%<#pragma omp target exit data%> must contain at least one " |
| 16322 | "%<map%> clause" ); |
| 16323 | return NULL_TREE; |
| 16324 | } |
| 16325 | |
| 16326 | tree stmt = make_node (OMP_TARGET_EXIT_DATA); |
| 16327 | TREE_TYPE (stmt) = void_type_node; |
| 16328 | OMP_TARGET_EXIT_DATA_CLAUSES (stmt) = clauses; |
| 16329 | SET_EXPR_LOCATION (stmt, loc); |
| 16330 | add_stmt (stmt); |
| 16331 | return stmt; |
| 16332 | } |
| 16333 | |
| 16334 | /* OpenMP 4.0: |
| 16335 | # pragma omp target target-clause[optseq] new-line |
| 16336 | structured-block */ |
| 16337 | |
| 16338 | #define OMP_TARGET_CLAUSE_MASK \ |
| 16339 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEVICE) \ |
| 16340 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MAP) \ |
| 16341 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
| 16342 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEPEND) \ |
| 16343 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOWAIT) \ |
| 16344 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 16345 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
| 16346 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULTMAP) \ |
| 16347 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IS_DEVICE_PTR)) |
| 16348 | |
| 16349 | static bool |
| 16350 | c_parser_omp_target (c_parser *parser, enum pragma_context context, bool *if_p) |
| 16351 | { |
| 16352 | location_t loc = c_parser_peek_token (parser)->location; |
| 16353 | c_parser_consume_pragma (parser); |
| 16354 | tree *pc = NULL, stmt, block; |
| 16355 | |
| 16356 | if (context != pragma_stmt && context != pragma_compound) |
| 16357 | { |
| 16358 | c_parser_error (parser, "expected declaration specifiers" ); |
| 16359 | c_parser_skip_to_pragma_eol (parser); |
| 16360 | return false; |
| 16361 | } |
| 16362 | |
| 16363 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 16364 | { |
| 16365 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 16366 | enum tree_code ccode = ERROR_MARK; |
| 16367 | |
| 16368 | if (strcmp (p, "teams" ) == 0) |
| 16369 | ccode = OMP_TEAMS; |
| 16370 | else if (strcmp (p, "parallel" ) == 0) |
| 16371 | ccode = OMP_PARALLEL; |
| 16372 | else if (strcmp (p, "simd" ) == 0) |
| 16373 | ccode = OMP_SIMD; |
| 16374 | if (ccode != ERROR_MARK) |
| 16375 | { |
| 16376 | tree cclauses[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 16377 | char p_name[sizeof ("#pragma omp target teams distribute " |
| 16378 | "parallel for simd" )]; |
| 16379 | |
| 16380 | c_parser_consume_token (parser); |
| 16381 | strcpy (p_name, "#pragma omp target" ); |
| 16382 | if (!flag_openmp) /* flag_openmp_simd */ |
| 16383 | { |
| 16384 | tree stmt; |
| 16385 | switch (ccode) |
| 16386 | { |
| 16387 | case OMP_TEAMS: |
| 16388 | stmt = c_parser_omp_teams (loc, parser, p_name, |
| 16389 | OMP_TARGET_CLAUSE_MASK, |
| 16390 | cclauses, if_p); |
| 16391 | break; |
| 16392 | case OMP_PARALLEL: |
| 16393 | stmt = c_parser_omp_parallel (loc, parser, p_name, |
| 16394 | OMP_TARGET_CLAUSE_MASK, |
| 16395 | cclauses, if_p); |
| 16396 | break; |
| 16397 | case OMP_SIMD: |
| 16398 | stmt = c_parser_omp_simd (loc, parser, p_name, |
| 16399 | OMP_TARGET_CLAUSE_MASK, |
| 16400 | cclauses, if_p); |
| 16401 | break; |
| 16402 | default: |
| 16403 | gcc_unreachable (); |
| 16404 | } |
| 16405 | return stmt != NULL_TREE; |
| 16406 | } |
| 16407 | keep_next_level (); |
| 16408 | tree block = c_begin_compound_stmt (true), ret; |
| 16409 | switch (ccode) |
| 16410 | { |
| 16411 | case OMP_TEAMS: |
| 16412 | ret = c_parser_omp_teams (loc, parser, p_name, |
| 16413 | OMP_TARGET_CLAUSE_MASK, cclauses, |
| 16414 | if_p); |
| 16415 | break; |
| 16416 | case OMP_PARALLEL: |
| 16417 | ret = c_parser_omp_parallel (loc, parser, p_name, |
| 16418 | OMP_TARGET_CLAUSE_MASK, cclauses, |
| 16419 | if_p); |
| 16420 | break; |
| 16421 | case OMP_SIMD: |
| 16422 | ret = c_parser_omp_simd (loc, parser, p_name, |
| 16423 | OMP_TARGET_CLAUSE_MASK, cclauses, |
| 16424 | if_p); |
| 16425 | break; |
| 16426 | default: |
| 16427 | gcc_unreachable (); |
| 16428 | } |
| 16429 | block = c_end_compound_stmt (loc, block, true); |
| 16430 | if (ret == NULL_TREE) |
| 16431 | return false; |
| 16432 | if (ccode == OMP_TEAMS) |
| 16433 | { |
| 16434 | /* For combined target teams, ensure the num_teams and |
| 16435 | thread_limit clause expressions are evaluated on the host, |
| 16436 | before entering the target construct. */ |
| 16437 | tree c; |
| 16438 | for (c = cclauses[C_OMP_CLAUSE_SPLIT_TEAMS]; |
| 16439 | c; c = OMP_CLAUSE_CHAIN (c)) |
| 16440 | if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_NUM_TEAMS |
| 16441 | || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_THREAD_LIMIT) |
| 16442 | && TREE_CODE (OMP_CLAUSE_OPERAND (c, 0)) != INTEGER_CST) |
| 16443 | { |
| 16444 | tree expr = OMP_CLAUSE_OPERAND (c, 0); |
| 16445 | tree tmp = create_tmp_var_raw (TREE_TYPE (expr)); |
| 16446 | expr = build4 (TARGET_EXPR, TREE_TYPE (expr), tmp, |
| 16447 | expr, NULL_TREE, NULL_TREE); |
| 16448 | add_stmt (expr); |
| 16449 | OMP_CLAUSE_OPERAND (c, 0) = expr; |
| 16450 | tree tc = build_omp_clause (OMP_CLAUSE_LOCATION (c), |
| 16451 | OMP_CLAUSE_FIRSTPRIVATE); |
| 16452 | OMP_CLAUSE_DECL (tc) = tmp; |
| 16453 | OMP_CLAUSE_CHAIN (tc) |
| 16454 | = cclauses[C_OMP_CLAUSE_SPLIT_TARGET]; |
| 16455 | cclauses[C_OMP_CLAUSE_SPLIT_TARGET] = tc; |
| 16456 | } |
| 16457 | } |
| 16458 | tree stmt = make_node (OMP_TARGET); |
| 16459 | TREE_TYPE (stmt) = void_type_node; |
| 16460 | OMP_TARGET_CLAUSES (stmt) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET]; |
| 16461 | OMP_TARGET_BODY (stmt) = block; |
| 16462 | OMP_TARGET_COMBINED (stmt) = 1; |
| 16463 | add_stmt (stmt); |
| 16464 | pc = &OMP_TARGET_CLAUSES (stmt); |
| 16465 | goto check_clauses; |
| 16466 | } |
| 16467 | else if (!flag_openmp) /* flag_openmp_simd */ |
| 16468 | { |
| 16469 | c_parser_skip_to_pragma_eol (parser, false); |
| 16470 | return false; |
| 16471 | } |
| 16472 | else if (strcmp (p, "data" ) == 0) |
| 16473 | { |
| 16474 | c_parser_consume_token (parser); |
| 16475 | c_parser_omp_target_data (loc, parser, if_p); |
| 16476 | return true; |
| 16477 | } |
| 16478 | else if (strcmp (p, "enter" ) == 0) |
| 16479 | { |
| 16480 | c_parser_consume_token (parser); |
| 16481 | c_parser_omp_target_enter_data (loc, parser, context); |
| 16482 | return false; |
| 16483 | } |
| 16484 | else if (strcmp (p, "exit" ) == 0) |
| 16485 | { |
| 16486 | c_parser_consume_token (parser); |
| 16487 | c_parser_omp_target_exit_data (loc, parser, context); |
| 16488 | return false; |
| 16489 | } |
| 16490 | else if (strcmp (p, "update" ) == 0) |
| 16491 | { |
| 16492 | c_parser_consume_token (parser); |
| 16493 | return c_parser_omp_target_update (loc, parser, context); |
| 16494 | } |
| 16495 | } |
| 16496 | if (!flag_openmp) /* flag_openmp_simd */ |
| 16497 | { |
| 16498 | c_parser_skip_to_pragma_eol (parser, false); |
| 16499 | return false; |
| 16500 | } |
| 16501 | |
| 16502 | stmt = make_node (OMP_TARGET); |
| 16503 | TREE_TYPE (stmt) = void_type_node; |
| 16504 | |
| 16505 | OMP_TARGET_CLAUSES (stmt) |
| 16506 | = c_parser_omp_all_clauses (parser, OMP_TARGET_CLAUSE_MASK, |
| 16507 | "#pragma omp target" ); |
| 16508 | pc = &OMP_TARGET_CLAUSES (stmt); |
| 16509 | keep_next_level (); |
| 16510 | block = c_begin_compound_stmt (true); |
| 16511 | add_stmt (c_parser_omp_structured_block (parser, if_p)); |
| 16512 | OMP_TARGET_BODY (stmt) = c_end_compound_stmt (loc, block, true); |
| 16513 | |
| 16514 | SET_EXPR_LOCATION (stmt, loc); |
| 16515 | add_stmt (stmt); |
| 16516 | |
| 16517 | check_clauses: |
| 16518 | while (*pc) |
| 16519 | { |
| 16520 | if (OMP_CLAUSE_CODE (*pc) == OMP_CLAUSE_MAP) |
| 16521 | switch (OMP_CLAUSE_MAP_KIND (*pc)) |
| 16522 | { |
| 16523 | case GOMP_MAP_TO: |
| 16524 | case GOMP_MAP_ALWAYS_TO: |
| 16525 | case GOMP_MAP_FROM: |
| 16526 | case GOMP_MAP_ALWAYS_FROM: |
| 16527 | case GOMP_MAP_TOFROM: |
| 16528 | case GOMP_MAP_ALWAYS_TOFROM: |
| 16529 | case GOMP_MAP_ALLOC: |
| 16530 | case GOMP_MAP_FIRSTPRIVATE_POINTER: |
| 16531 | case GOMP_MAP_ALWAYS_POINTER: |
| 16532 | break; |
| 16533 | default: |
| 16534 | error_at (OMP_CLAUSE_LOCATION (*pc), |
| 16535 | "%<#pragma omp target%> with map-type other " |
| 16536 | "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> " |
| 16537 | "on %<map%> clause" ); |
| 16538 | *pc = OMP_CLAUSE_CHAIN (*pc); |
| 16539 | continue; |
| 16540 | } |
| 16541 | pc = &OMP_CLAUSE_CHAIN (*pc); |
| 16542 | } |
| 16543 | return true; |
| 16544 | } |
| 16545 | |
| 16546 | /* OpenMP 4.0: |
| 16547 | # pragma omp declare simd declare-simd-clauses[optseq] new-line */ |
| 16548 | |
| 16549 | #define OMP_DECLARE_SIMD_CLAUSE_MASK \ |
| 16550 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SIMDLEN) \ |
| 16551 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINEAR) \ |
| 16552 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_ALIGNED) \ |
| 16553 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNIFORM) \ |
| 16554 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_INBRANCH) \ |
| 16555 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOTINBRANCH)) |
| 16556 | |
| 16557 | static void |
| 16558 | c_parser_omp_declare_simd (c_parser *parser, enum pragma_context context) |
| 16559 | { |
| 16560 | auto_vec<c_token> clauses; |
| 16561 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
| 16562 | { |
| 16563 | c_token *token = c_parser_peek_token (parser); |
| 16564 | if (token->type == CPP_EOF) |
| 16565 | { |
| 16566 | c_parser_skip_to_pragma_eol (parser); |
| 16567 | return; |
| 16568 | } |
| 16569 | clauses.safe_push (*token); |
| 16570 | c_parser_consume_token (parser); |
| 16571 | } |
| 16572 | clauses.safe_push (*c_parser_peek_token (parser)); |
| 16573 | c_parser_skip_to_pragma_eol (parser); |
| 16574 | |
| 16575 | while (c_parser_next_token_is (parser, CPP_PRAGMA)) |
| 16576 | { |
| 16577 | if (c_parser_peek_token (parser)->pragma_kind |
| 16578 | != PRAGMA_OMP_DECLARE |
| 16579 | || c_parser_peek_2nd_token (parser)->type != CPP_NAME |
| 16580 | || strcmp (IDENTIFIER_POINTER |
| 16581 | (c_parser_peek_2nd_token (parser)->value), |
| 16582 | "simd" ) != 0) |
| 16583 | { |
| 16584 | c_parser_error (parser, |
| 16585 | "%<#pragma omp declare simd%> must be followed by " |
| 16586 | "function declaration or definition or another " |
| 16587 | "%<#pragma omp declare simd%>" ); |
| 16588 | return; |
| 16589 | } |
| 16590 | c_parser_consume_pragma (parser); |
| 16591 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
| 16592 | { |
| 16593 | c_token *token = c_parser_peek_token (parser); |
| 16594 | if (token->type == CPP_EOF) |
| 16595 | { |
| 16596 | c_parser_skip_to_pragma_eol (parser); |
| 16597 | return; |
| 16598 | } |
| 16599 | clauses.safe_push (*token); |
| 16600 | c_parser_consume_token (parser); |
| 16601 | } |
| 16602 | clauses.safe_push (*c_parser_peek_token (parser)); |
| 16603 | c_parser_skip_to_pragma_eol (parser); |
| 16604 | } |
| 16605 | |
| 16606 | /* Make sure nothing tries to read past the end of the tokens. */ |
| 16607 | c_token eof_token; |
| 16608 | memset (&eof_token, 0, sizeof (eof_token)); |
| 16609 | eof_token.type = CPP_EOF; |
| 16610 | clauses.safe_push (eof_token); |
| 16611 | clauses.safe_push (eof_token); |
| 16612 | |
| 16613 | switch (context) |
| 16614 | { |
| 16615 | case pragma_external: |
| 16616 | if (c_parser_next_token_is (parser, CPP_KEYWORD) |
| 16617 | && c_parser_peek_token (parser)->keyword == RID_EXTENSION) |
| 16618 | { |
| 16619 | int ext = disable_extension_diagnostics (); |
| 16620 | do |
| 16621 | c_parser_consume_token (parser); |
| 16622 | while (c_parser_next_token_is (parser, CPP_KEYWORD) |
| 16623 | && c_parser_peek_token (parser)->keyword == RID_EXTENSION); |
| 16624 | c_parser_declaration_or_fndef (parser, true, true, true, false, true, |
| 16625 | NULL, clauses); |
| 16626 | restore_extension_diagnostics (ext); |
| 16627 | } |
| 16628 | else |
| 16629 | c_parser_declaration_or_fndef (parser, true, true, true, false, true, |
| 16630 | NULL, clauses); |
| 16631 | break; |
| 16632 | case pragma_struct: |
| 16633 | case pragma_param: |
| 16634 | c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by " |
| 16635 | "function declaration or definition" ); |
| 16636 | break; |
| 16637 | case pragma_compound: |
| 16638 | case pragma_stmt: |
| 16639 | if (c_parser_next_token_is (parser, CPP_KEYWORD) |
| 16640 | && c_parser_peek_token (parser)->keyword == RID_EXTENSION) |
| 16641 | { |
| 16642 | int ext = disable_extension_diagnostics (); |
| 16643 | do |
| 16644 | c_parser_consume_token (parser); |
| 16645 | while (c_parser_next_token_is (parser, CPP_KEYWORD) |
| 16646 | && c_parser_peek_token (parser)->keyword == RID_EXTENSION); |
| 16647 | if (c_parser_next_tokens_start_declaration (parser)) |
| 16648 | { |
| 16649 | c_parser_declaration_or_fndef (parser, true, true, true, true, |
| 16650 | true, NULL, clauses); |
| 16651 | restore_extension_diagnostics (ext); |
| 16652 | break; |
| 16653 | } |
| 16654 | restore_extension_diagnostics (ext); |
| 16655 | } |
| 16656 | else if (c_parser_next_tokens_start_declaration (parser)) |
| 16657 | { |
| 16658 | c_parser_declaration_or_fndef (parser, true, true, true, true, true, |
| 16659 | NULL, clauses); |
| 16660 | break; |
| 16661 | } |
| 16662 | c_parser_error (parser, "%<#pragma omp declare simd%> must be followed by " |
| 16663 | "function declaration or definition" ); |
| 16664 | break; |
| 16665 | default: |
| 16666 | gcc_unreachable (); |
| 16667 | } |
| 16668 | } |
| 16669 | |
| 16670 | /* Finalize #pragma omp declare simd clauses after FNDECL has been parsed, |
| 16671 | and put that into "omp declare simd" attribute. */ |
| 16672 | |
| 16673 | static void |
| 16674 | c_finish_omp_declare_simd (c_parser *parser, tree fndecl, tree parms, |
| 16675 | vec<c_token> clauses) |
| 16676 | { |
| 16677 | if (flag_cilkplus |
| 16678 | && (clauses.exists () |
| 16679 | || lookup_attribute ("simd" , DECL_ATTRIBUTES (fndecl))) |
| 16680 | && !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) |
| 16681 | { |
| 16682 | error ("%<#pragma omp declare simd%> or %<simd%> attribute cannot be " |
| 16683 | "used in the same function marked as a Cilk Plus SIMD-enabled " |
| 16684 | "function" ); |
| 16685 | vec_free (parser->cilk_simd_fn_tokens); |
| 16686 | return; |
| 16687 | } |
| 16688 | |
| 16689 | /* Normally first token is CPP_NAME "simd". CPP_EOF there indicates |
| 16690 | error has been reported and CPP_PRAGMA that c_finish_omp_declare_simd |
| 16691 | has already processed the tokens. */ |
| 16692 | if (clauses.exists () && clauses[0].type == CPP_EOF) |
| 16693 | return; |
| 16694 | if (fndecl == NULL_TREE || TREE_CODE (fndecl) != FUNCTION_DECL) |
| 16695 | { |
| 16696 | error ("%<#pragma omp declare simd%> not immediately followed by " |
| 16697 | "a function declaration or definition" ); |
| 16698 | clauses[0].type = CPP_EOF; |
| 16699 | return; |
| 16700 | } |
| 16701 | if (clauses.exists () && clauses[0].type != CPP_NAME) |
| 16702 | { |
| 16703 | error_at (DECL_SOURCE_LOCATION (fndecl), |
| 16704 | "%<#pragma omp declare simd%> not immediately followed by " |
| 16705 | "a single function declaration or definition" ); |
| 16706 | clauses[0].type = CPP_EOF; |
| 16707 | return; |
| 16708 | } |
| 16709 | |
| 16710 | if (parms == NULL_TREE) |
| 16711 | parms = DECL_ARGUMENTS (fndecl); |
| 16712 | |
| 16713 | unsigned int tokens_avail = parser->tokens_avail; |
| 16714 | gcc_assert (parser->tokens == &parser->tokens_buf[0]); |
| 16715 | bool is_cilkplus_cilk_simd_fn = false; |
| 16716 | |
| 16717 | if (flag_cilkplus && !vec_safe_is_empty (parser->cilk_simd_fn_tokens)) |
| 16718 | { |
| 16719 | parser->tokens = parser->cilk_simd_fn_tokens->address (); |
| 16720 | parser->tokens_avail = vec_safe_length (parser->cilk_simd_fn_tokens); |
| 16721 | is_cilkplus_cilk_simd_fn = true; |
| 16722 | |
| 16723 | if (lookup_attribute ("simd" , DECL_ATTRIBUTES (fndecl)) != NULL) |
| 16724 | { |
| 16725 | error_at (DECL_SOURCE_LOCATION (fndecl), |
| 16726 | "%<__simd__%> attribute cannot be used in the same " |
| 16727 | "function marked as a Cilk Plus SIMD-enabled function" ); |
| 16728 | vec_free (parser->cilk_simd_fn_tokens); |
| 16729 | return; |
| 16730 | } |
| 16731 | |
| 16732 | } |
| 16733 | else |
| 16734 | { |
| 16735 | parser->tokens = clauses.address (); |
| 16736 | parser->tokens_avail = clauses.length (); |
| 16737 | } |
| 16738 | |
| 16739 | /* c_parser_omp_declare_simd pushed 2 extra CPP_EOF tokens at the end. */ |
| 16740 | while (parser->tokens_avail > 3) |
| 16741 | { |
| 16742 | c_token *token = c_parser_peek_token (parser); |
| 16743 | if (!is_cilkplus_cilk_simd_fn) |
| 16744 | gcc_assert (token->type == CPP_NAME |
| 16745 | && strcmp (IDENTIFIER_POINTER (token->value), "simd" ) == 0); |
| 16746 | else |
| 16747 | gcc_assert (token->type == CPP_NAME |
| 16748 | && is_cilkplus_vector_p (token->value)); |
| 16749 | c_parser_consume_token (parser); |
| 16750 | parser->in_pragma = true; |
| 16751 | |
| 16752 | tree c = NULL_TREE; |
| 16753 | if (is_cilkplus_cilk_simd_fn) |
| 16754 | c = c_parser_omp_all_clauses (parser, CILK_SIMD_FN_CLAUSE_MASK, |
| 16755 | "SIMD-enabled functions attribute" ); |
| 16756 | else |
| 16757 | c = c_parser_omp_all_clauses (parser, OMP_DECLARE_SIMD_CLAUSE_MASK, |
| 16758 | "#pragma omp declare simd" ); |
| 16759 | c = c_omp_declare_simd_clauses_to_numbers (parms, c); |
| 16760 | if (c != NULL_TREE) |
| 16761 | c = tree_cons (NULL_TREE, c, NULL_TREE); |
| 16762 | if (is_cilkplus_cilk_simd_fn) |
| 16763 | { |
| 16764 | tree k = build_tree_list (get_identifier ("cilk simd function" ), |
| 16765 | NULL_TREE); |
| 16766 | TREE_CHAIN (k) = DECL_ATTRIBUTES (fndecl); |
| 16767 | DECL_ATTRIBUTES (fndecl) = k; |
| 16768 | } |
| 16769 | c = build_tree_list (get_identifier ("omp declare simd" ), c); |
| 16770 | TREE_CHAIN (c) = DECL_ATTRIBUTES (fndecl); |
| 16771 | DECL_ATTRIBUTES (fndecl) = c; |
| 16772 | } |
| 16773 | |
| 16774 | parser->tokens = &parser->tokens_buf[0]; |
| 16775 | parser->tokens_avail = tokens_avail; |
| 16776 | if (clauses.exists ()) |
| 16777 | clauses[0].type = CPP_PRAGMA; |
| 16778 | |
| 16779 | if (!vec_safe_is_empty (parser->cilk_simd_fn_tokens)) |
| 16780 | vec_free (parser->cilk_simd_fn_tokens); |
| 16781 | } |
| 16782 | |
| 16783 | |
| 16784 | /* OpenMP 4.0: |
| 16785 | # pragma omp declare target new-line |
| 16786 | declarations and definitions |
| 16787 | # pragma omp end declare target new-line |
| 16788 | |
| 16789 | OpenMP 4.5: |
| 16790 | # pragma omp declare target ( extended-list ) new-line |
| 16791 | |
| 16792 | # pragma omp declare target declare-target-clauses[seq] new-line */ |
| 16793 | |
| 16794 | #define OMP_DECLARE_TARGET_CLAUSE_MASK \ |
| 16795 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_TO) \ |
| 16796 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LINK)) |
| 16797 | |
| 16798 | static void |
| 16799 | c_parser_omp_declare_target (c_parser *parser) |
| 16800 | { |
| 16801 | location_t loc = c_parser_peek_token (parser)->location; |
| 16802 | tree clauses = NULL_TREE; |
| 16803 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 16804 | clauses = c_parser_omp_all_clauses (parser, OMP_DECLARE_TARGET_CLAUSE_MASK, |
| 16805 | "#pragma omp declare target" ); |
| 16806 | else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) |
| 16807 | { |
| 16808 | clauses = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_TO_DECLARE, |
| 16809 | clauses); |
| 16810 | clauses = c_finish_omp_clauses (clauses, C_ORT_OMP); |
| 16811 | c_parser_skip_to_pragma_eol (parser); |
| 16812 | } |
| 16813 | else |
| 16814 | { |
| 16815 | c_parser_skip_to_pragma_eol (parser); |
| 16816 | current_omp_declare_target_attribute++; |
| 16817 | return; |
| 16818 | } |
| 16819 | if (current_omp_declare_target_attribute) |
| 16820 | error_at (loc, "%<#pragma omp declare target%> with clauses in between " |
| 16821 | "%<#pragma omp declare target%> without clauses and " |
| 16822 | "%<#pragma omp end declare target%>" ); |
| 16823 | for (tree c = clauses; c; c = OMP_CLAUSE_CHAIN (c)) |
| 16824 | { |
| 16825 | tree t = OMP_CLAUSE_DECL (c), id; |
| 16826 | tree at1 = lookup_attribute ("omp declare target" , DECL_ATTRIBUTES (t)); |
| 16827 | tree at2 = lookup_attribute ("omp declare target link" , |
| 16828 | DECL_ATTRIBUTES (t)); |
| 16829 | if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINK) |
| 16830 | { |
| 16831 | id = get_identifier ("omp declare target link" ); |
| 16832 | std::swap (at1, at2); |
| 16833 | } |
| 16834 | else |
| 16835 | id = get_identifier ("omp declare target" ); |
| 16836 | if (at2) |
| 16837 | { |
| 16838 | error_at (OMP_CLAUSE_LOCATION (c), |
| 16839 | "%qD specified both in declare target %<link%> and %<to%>" |
| 16840 | " clauses" , t); |
| 16841 | continue; |
| 16842 | } |
| 16843 | if (!at1) |
| 16844 | { |
| 16845 | DECL_ATTRIBUTES (t) = tree_cons (id, NULL_TREE, DECL_ATTRIBUTES (t)); |
| 16846 | if (TREE_CODE (t) != FUNCTION_DECL && !is_global_var (t)) |
| 16847 | continue; |
| 16848 | |
| 16849 | symtab_node *node = symtab_node::get (t); |
| 16850 | if (node != NULL) |
| 16851 | { |
| 16852 | node->offloadable = 1; |
| 16853 | if (ENABLE_OFFLOADING) |
| 16854 | { |
| 16855 | g->have_offload = true; |
| 16856 | if (is_a <varpool_node *> (node)) |
| 16857 | vec_safe_push (offload_vars, t); |
| 16858 | } |
| 16859 | } |
| 16860 | } |
| 16861 | } |
| 16862 | } |
| 16863 | |
| 16864 | static void |
| 16865 | c_parser_omp_end_declare_target (c_parser *parser) |
| 16866 | { |
| 16867 | location_t loc = c_parser_peek_token (parser)->location; |
| 16868 | c_parser_consume_pragma (parser); |
| 16869 | if (c_parser_next_token_is (parser, CPP_NAME) |
| 16870 | && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value), |
| 16871 | "declare" ) == 0) |
| 16872 | { |
| 16873 | c_parser_consume_token (parser); |
| 16874 | if (c_parser_next_token_is (parser, CPP_NAME) |
| 16875 | && strcmp (IDENTIFIER_POINTER (c_parser_peek_token (parser)->value), |
| 16876 | "target" ) == 0) |
| 16877 | c_parser_consume_token (parser); |
| 16878 | else |
| 16879 | { |
| 16880 | c_parser_error (parser, "expected %<target%>" ); |
| 16881 | c_parser_skip_to_pragma_eol (parser); |
| 16882 | return; |
| 16883 | } |
| 16884 | } |
| 16885 | else |
| 16886 | { |
| 16887 | c_parser_error (parser, "expected %<declare%>" ); |
| 16888 | c_parser_skip_to_pragma_eol (parser); |
| 16889 | return; |
| 16890 | } |
| 16891 | c_parser_skip_to_pragma_eol (parser); |
| 16892 | if (!current_omp_declare_target_attribute) |
| 16893 | error_at (loc, "%<#pragma omp end declare target%> without corresponding " |
| 16894 | "%<#pragma omp declare target%>" ); |
| 16895 | else |
| 16896 | current_omp_declare_target_attribute--; |
| 16897 | } |
| 16898 | |
| 16899 | |
| 16900 | /* OpenMP 4.0 |
| 16901 | #pragma omp declare reduction (reduction-id : typename-list : expression) \ |
| 16902 | initializer-clause[opt] new-line |
| 16903 | |
| 16904 | initializer-clause: |
| 16905 | initializer (omp_priv = initializer) |
| 16906 | initializer (function-name (argument-list)) */ |
| 16907 | |
| 16908 | static void |
| 16909 | c_parser_omp_declare_reduction (c_parser *parser, enum pragma_context context) |
| 16910 | { |
| 16911 | unsigned int tokens_avail = 0, i; |
| 16912 | vec<tree> types = vNULL; |
| 16913 | vec<c_token> clauses = vNULL; |
| 16914 | enum tree_code reduc_code = ERROR_MARK; |
| 16915 | tree reduc_id = NULL_TREE; |
| 16916 | tree type; |
| 16917 | location_t rloc = c_parser_peek_token (parser)->location; |
| 16918 | |
| 16919 | if (context == pragma_struct || context == pragma_param) |
| 16920 | { |
| 16921 | error ("%<#pragma omp declare reduction%> not at file or block scope" ); |
| 16922 | goto fail; |
| 16923 | } |
| 16924 | |
| 16925 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 16926 | goto fail; |
| 16927 | |
| 16928 | switch (c_parser_peek_token (parser)->type) |
| 16929 | { |
| 16930 | case CPP_PLUS: |
| 16931 | reduc_code = PLUS_EXPR; |
| 16932 | break; |
| 16933 | case CPP_MULT: |
| 16934 | reduc_code = MULT_EXPR; |
| 16935 | break; |
| 16936 | case CPP_MINUS: |
| 16937 | reduc_code = MINUS_EXPR; |
| 16938 | break; |
| 16939 | case CPP_AND: |
| 16940 | reduc_code = BIT_AND_EXPR; |
| 16941 | break; |
| 16942 | case CPP_XOR: |
| 16943 | reduc_code = BIT_XOR_EXPR; |
| 16944 | break; |
| 16945 | case CPP_OR: |
| 16946 | reduc_code = BIT_IOR_EXPR; |
| 16947 | break; |
| 16948 | case CPP_AND_AND: |
| 16949 | reduc_code = TRUTH_ANDIF_EXPR; |
| 16950 | break; |
| 16951 | case CPP_OR_OR: |
| 16952 | reduc_code = TRUTH_ORIF_EXPR; |
| 16953 | break; |
| 16954 | case CPP_NAME: |
| 16955 | const char *p; |
| 16956 | p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 16957 | if (strcmp (p, "min" ) == 0) |
| 16958 | { |
| 16959 | reduc_code = MIN_EXPR; |
| 16960 | break; |
| 16961 | } |
| 16962 | if (strcmp (p, "max" ) == 0) |
| 16963 | { |
| 16964 | reduc_code = MAX_EXPR; |
| 16965 | break; |
| 16966 | } |
| 16967 | reduc_id = c_parser_peek_token (parser)->value; |
| 16968 | break; |
| 16969 | default: |
| 16970 | c_parser_error (parser, |
| 16971 | "expected %<+%>, %<*%>, %<-%>, %<&%>, " |
| 16972 | "%<^%>, %<|%>, %<&&%>, %<||%> or identifier" ); |
| 16973 | goto fail; |
| 16974 | } |
| 16975 | |
| 16976 | tree orig_reduc_id, reduc_decl; |
| 16977 | orig_reduc_id = reduc_id; |
| 16978 | reduc_id = c_omp_reduction_id (reduc_code, reduc_id); |
| 16979 | reduc_decl = c_omp_reduction_decl (reduc_id); |
| 16980 | c_parser_consume_token (parser); |
| 16981 | |
| 16982 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>" )) |
| 16983 | goto fail; |
| 16984 | |
| 16985 | while (true) |
| 16986 | { |
| 16987 | location_t loc = c_parser_peek_token (parser)->location; |
| 16988 | struct c_type_name *ctype = c_parser_type_name (parser); |
| 16989 | if (ctype != NULL) |
| 16990 | { |
| 16991 | type = groktypename (ctype, NULL, NULL); |
| 16992 | if (type == error_mark_node) |
| 16993 | ; |
| 16994 | else if ((INTEGRAL_TYPE_P (type) |
| 16995 | || TREE_CODE (type) == REAL_TYPE |
| 16996 | || TREE_CODE (type) == COMPLEX_TYPE) |
| 16997 | && orig_reduc_id == NULL_TREE) |
| 16998 | error_at (loc, "predeclared arithmetic type in " |
| 16999 | "%<#pragma omp declare reduction%>" ); |
| 17000 | else if (TREE_CODE (type) == FUNCTION_TYPE |
| 17001 | || TREE_CODE (type) == ARRAY_TYPE) |
| 17002 | error_at (loc, "function or array type in " |
| 17003 | "%<#pragma omp declare reduction%>" ); |
| 17004 | else if (TYPE_ATOMIC (type)) |
| 17005 | error_at (loc, "%<_Atomic%> qualified type in " |
| 17006 | "%<#pragma omp declare reduction%>" ); |
| 17007 | else if (TYPE_QUALS_NO_ADDR_SPACE (type)) |
| 17008 | error_at (loc, "const, volatile or restrict qualified type in " |
| 17009 | "%<#pragma omp declare reduction%>" ); |
| 17010 | else |
| 17011 | { |
| 17012 | tree t; |
| 17013 | for (t = DECL_INITIAL (reduc_decl); t; t = TREE_CHAIN (t)) |
| 17014 | if (comptypes (TREE_PURPOSE (t), type)) |
| 17015 | { |
| 17016 | error_at (loc, "redeclaration of %qs " |
| 17017 | "%<#pragma omp declare reduction%> for " |
| 17018 | "type %qT" , |
| 17019 | IDENTIFIER_POINTER (reduc_id) |
| 17020 | + sizeof ("omp declare reduction " ) - 1, |
| 17021 | type); |
| 17022 | location_t ploc |
| 17023 | = DECL_SOURCE_LOCATION (TREE_VEC_ELT (TREE_VALUE (t), |
| 17024 | 0)); |
| 17025 | error_at (ploc, "previous %<#pragma omp declare " |
| 17026 | "reduction%>" ); |
| 17027 | break; |
| 17028 | } |
| 17029 | if (t == NULL_TREE) |
| 17030 | types.safe_push (type); |
| 17031 | } |
| 17032 | if (c_parser_next_token_is (parser, CPP_COMMA)) |
| 17033 | c_parser_consume_token (parser); |
| 17034 | else |
| 17035 | break; |
| 17036 | } |
| 17037 | else |
| 17038 | break; |
| 17039 | } |
| 17040 | |
| 17041 | if (!c_parser_require (parser, CPP_COLON, "expected %<:%>" ) |
| 17042 | || types.is_empty ()) |
| 17043 | { |
| 17044 | fail: |
| 17045 | clauses.release (); |
| 17046 | types.release (); |
| 17047 | while (true) |
| 17048 | { |
| 17049 | c_token *token = c_parser_peek_token (parser); |
| 17050 | if (token->type == CPP_EOF || token->type == CPP_PRAGMA_EOL) |
| 17051 | break; |
| 17052 | c_parser_consume_token (parser); |
| 17053 | } |
| 17054 | c_parser_skip_to_pragma_eol (parser); |
| 17055 | return; |
| 17056 | } |
| 17057 | |
| 17058 | if (types.length () > 1) |
| 17059 | { |
| 17060 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
| 17061 | { |
| 17062 | c_token *token = c_parser_peek_token (parser); |
| 17063 | if (token->type == CPP_EOF) |
| 17064 | goto fail; |
| 17065 | clauses.safe_push (*token); |
| 17066 | c_parser_consume_token (parser); |
| 17067 | } |
| 17068 | clauses.safe_push (*c_parser_peek_token (parser)); |
| 17069 | c_parser_skip_to_pragma_eol (parser); |
| 17070 | |
| 17071 | /* Make sure nothing tries to read past the end of the tokens. */ |
| 17072 | c_token eof_token; |
| 17073 | memset (&eof_token, 0, sizeof (eof_token)); |
| 17074 | eof_token.type = CPP_EOF; |
| 17075 | clauses.safe_push (eof_token); |
| 17076 | clauses.safe_push (eof_token); |
| 17077 | } |
| 17078 | |
| 17079 | int errs = errorcount; |
| 17080 | FOR_EACH_VEC_ELT (types, i, type) |
| 17081 | { |
| 17082 | tokens_avail = parser->tokens_avail; |
| 17083 | gcc_assert (parser->tokens == &parser->tokens_buf[0]); |
| 17084 | if (!clauses.is_empty ()) |
| 17085 | { |
| 17086 | parser->tokens = clauses.address (); |
| 17087 | parser->tokens_avail = clauses.length (); |
| 17088 | parser->in_pragma = true; |
| 17089 | } |
| 17090 | |
| 17091 | bool nested = current_function_decl != NULL_TREE; |
| 17092 | if (nested) |
| 17093 | c_push_function_context (); |
| 17094 | tree fndecl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL, |
| 17095 | reduc_id, default_function_type); |
| 17096 | current_function_decl = fndecl; |
| 17097 | allocate_struct_function (fndecl, true); |
| 17098 | push_scope (); |
| 17099 | tree stmt = push_stmt_list (); |
| 17100 | /* Intentionally BUILTINS_LOCATION, so that -Wshadow doesn't |
| 17101 | warn about these. */ |
| 17102 | tree omp_out = build_decl (BUILTINS_LOCATION, VAR_DECL, |
| 17103 | get_identifier ("omp_out" ), type); |
| 17104 | DECL_ARTIFICIAL (omp_out) = 1; |
| 17105 | DECL_CONTEXT (omp_out) = fndecl; |
| 17106 | pushdecl (omp_out); |
| 17107 | tree omp_in = build_decl (BUILTINS_LOCATION, VAR_DECL, |
| 17108 | get_identifier ("omp_in" ), type); |
| 17109 | DECL_ARTIFICIAL (omp_in) = 1; |
| 17110 | DECL_CONTEXT (omp_in) = fndecl; |
| 17111 | pushdecl (omp_in); |
| 17112 | struct c_expr combiner = c_parser_expression (parser); |
| 17113 | struct c_expr initializer; |
| 17114 | tree omp_priv = NULL_TREE, omp_orig = NULL_TREE; |
| 17115 | bool bad = false; |
| 17116 | initializer.value = error_mark_node; |
| 17117 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>" )) |
| 17118 | bad = true; |
| 17119 | else if (c_parser_next_token_is (parser, CPP_NAME) |
| 17120 | && strcmp (IDENTIFIER_POINTER |
| 17121 | (c_parser_peek_token (parser)->value), |
| 17122 | "initializer" ) == 0) |
| 17123 | { |
| 17124 | c_parser_consume_token (parser); |
| 17125 | pop_scope (); |
| 17126 | push_scope (); |
| 17127 | omp_priv = build_decl (BUILTINS_LOCATION, VAR_DECL, |
| 17128 | get_identifier ("omp_priv" ), type); |
| 17129 | DECL_ARTIFICIAL (omp_priv) = 1; |
| 17130 | DECL_INITIAL (omp_priv) = error_mark_node; |
| 17131 | DECL_CONTEXT (omp_priv) = fndecl; |
| 17132 | pushdecl (omp_priv); |
| 17133 | omp_orig = build_decl (BUILTINS_LOCATION, VAR_DECL, |
| 17134 | get_identifier ("omp_orig" ), type); |
| 17135 | DECL_ARTIFICIAL (omp_orig) = 1; |
| 17136 | DECL_CONTEXT (omp_orig) = fndecl; |
| 17137 | pushdecl (omp_orig); |
| 17138 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 17139 | bad = true; |
| 17140 | else if (!c_parser_next_token_is (parser, CPP_NAME)) |
| 17141 | { |
| 17142 | c_parser_error (parser, "expected %<omp_priv%> or " |
| 17143 | "function-name" ); |
| 17144 | bad = true; |
| 17145 | } |
| 17146 | else if (strcmp (IDENTIFIER_POINTER |
| 17147 | (c_parser_peek_token (parser)->value), |
| 17148 | "omp_priv" ) != 0) |
| 17149 | { |
| 17150 | if (c_parser_peek_2nd_token (parser)->type != CPP_OPEN_PAREN |
| 17151 | || c_parser_peek_token (parser)->id_kind != C_ID_ID) |
| 17152 | { |
| 17153 | c_parser_error (parser, "expected function-name %<(%>" ); |
| 17154 | bad = true; |
| 17155 | } |
| 17156 | else |
| 17157 | initializer = c_parser_postfix_expression (parser); |
| 17158 | if (initializer.value |
| 17159 | && TREE_CODE (initializer.value) == CALL_EXPR) |
| 17160 | { |
| 17161 | int j; |
| 17162 | tree c = initializer.value; |
| 17163 | for (j = 0; j < call_expr_nargs (c); j++) |
| 17164 | { |
| 17165 | tree a = CALL_EXPR_ARG (c, j); |
| 17166 | STRIP_NOPS (a); |
| 17167 | if (TREE_CODE (a) == ADDR_EXPR |
| 17168 | && TREE_OPERAND (a, 0) == omp_priv) |
| 17169 | break; |
| 17170 | } |
| 17171 | if (j == call_expr_nargs (c)) |
| 17172 | error ("one of the initializer call arguments should be " |
| 17173 | "%<&omp_priv%>" ); |
| 17174 | } |
| 17175 | } |
| 17176 | else |
| 17177 | { |
| 17178 | c_parser_consume_token (parser); |
| 17179 | if (!c_parser_require (parser, CPP_EQ, "expected %<=%>" )) |
| 17180 | bad = true; |
| 17181 | else |
| 17182 | { |
| 17183 | tree st = push_stmt_list (); |
| 17184 | location_t loc = c_parser_peek_token (parser)->location; |
| 17185 | rich_location richloc (line_table, loc); |
| 17186 | start_init (omp_priv, NULL_TREE, 0, &richloc); |
| 17187 | struct c_expr init = c_parser_initializer (parser); |
| 17188 | finish_init (); |
| 17189 | finish_decl (omp_priv, loc, init.value, |
| 17190 | init.original_type, NULL_TREE); |
| 17191 | pop_stmt_list (st); |
| 17192 | } |
| 17193 | } |
| 17194 | if (!bad |
| 17195 | && !c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>" )) |
| 17196 | bad = true; |
| 17197 | } |
| 17198 | |
| 17199 | if (!bad) |
| 17200 | { |
| 17201 | c_parser_skip_to_pragma_eol (parser); |
| 17202 | |
| 17203 | tree t = tree_cons (type, make_tree_vec (omp_priv ? 6 : 3), |
| 17204 | DECL_INITIAL (reduc_decl)); |
| 17205 | DECL_INITIAL (reduc_decl) = t; |
| 17206 | DECL_SOURCE_LOCATION (omp_out) = rloc; |
| 17207 | TREE_VEC_ELT (TREE_VALUE (t), 0) = omp_out; |
| 17208 | TREE_VEC_ELT (TREE_VALUE (t), 1) = omp_in; |
| 17209 | TREE_VEC_ELT (TREE_VALUE (t), 2) = combiner.value; |
| 17210 | walk_tree (&combiner.value, c_check_omp_declare_reduction_r, |
| 17211 | &TREE_VEC_ELT (TREE_VALUE (t), 0), NULL); |
| 17212 | if (omp_priv) |
| 17213 | { |
| 17214 | DECL_SOURCE_LOCATION (omp_priv) = rloc; |
| 17215 | TREE_VEC_ELT (TREE_VALUE (t), 3) = omp_priv; |
| 17216 | TREE_VEC_ELT (TREE_VALUE (t), 4) = omp_orig; |
| 17217 | TREE_VEC_ELT (TREE_VALUE (t), 5) = initializer.value; |
| 17218 | walk_tree (&initializer.value, c_check_omp_declare_reduction_r, |
| 17219 | &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL); |
| 17220 | walk_tree (&DECL_INITIAL (omp_priv), |
| 17221 | c_check_omp_declare_reduction_r, |
| 17222 | &TREE_VEC_ELT (TREE_VALUE (t), 3), NULL); |
| 17223 | } |
| 17224 | } |
| 17225 | |
| 17226 | pop_stmt_list (stmt); |
| 17227 | pop_scope (); |
| 17228 | if (cfun->language != NULL) |
| 17229 | { |
| 17230 | ggc_free (cfun->language); |
| 17231 | cfun->language = NULL; |
| 17232 | } |
| 17233 | set_cfun (NULL); |
| 17234 | current_function_decl = NULL_TREE; |
| 17235 | if (nested) |
| 17236 | c_pop_function_context (); |
| 17237 | |
| 17238 | if (!clauses.is_empty ()) |
| 17239 | { |
| 17240 | parser->tokens = &parser->tokens_buf[0]; |
| 17241 | parser->tokens_avail = tokens_avail; |
| 17242 | } |
| 17243 | if (bad) |
| 17244 | goto fail; |
| 17245 | if (errs != errorcount) |
| 17246 | break; |
| 17247 | } |
| 17248 | |
| 17249 | clauses.release (); |
| 17250 | types.release (); |
| 17251 | } |
| 17252 | |
| 17253 | |
| 17254 | /* OpenMP 4.0 |
| 17255 | #pragma omp declare simd declare-simd-clauses[optseq] new-line |
| 17256 | #pragma omp declare reduction (reduction-id : typename-list : expression) \ |
| 17257 | initializer-clause[opt] new-line |
| 17258 | #pragma omp declare target new-line */ |
| 17259 | |
| 17260 | static void |
| 17261 | c_parser_omp_declare (c_parser *parser, enum pragma_context context) |
| 17262 | { |
| 17263 | c_parser_consume_pragma (parser); |
| 17264 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 17265 | { |
| 17266 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 17267 | if (strcmp (p, "simd" ) == 0) |
| 17268 | { |
| 17269 | /* c_parser_consume_token (parser); done in |
| 17270 | c_parser_omp_declare_simd. */ |
| 17271 | c_parser_omp_declare_simd (parser, context); |
| 17272 | return; |
| 17273 | } |
| 17274 | if (strcmp (p, "reduction" ) == 0) |
| 17275 | { |
| 17276 | c_parser_consume_token (parser); |
| 17277 | c_parser_omp_declare_reduction (parser, context); |
| 17278 | return; |
| 17279 | } |
| 17280 | if (!flag_openmp) /* flag_openmp_simd */ |
| 17281 | { |
| 17282 | c_parser_skip_to_pragma_eol (parser, false); |
| 17283 | return; |
| 17284 | } |
| 17285 | if (strcmp (p, "target" ) == 0) |
| 17286 | { |
| 17287 | c_parser_consume_token (parser); |
| 17288 | c_parser_omp_declare_target (parser); |
| 17289 | return; |
| 17290 | } |
| 17291 | } |
| 17292 | |
| 17293 | c_parser_error (parser, "expected %<simd%> or %<reduction%> " |
| 17294 | "or %<target%>" ); |
| 17295 | c_parser_skip_to_pragma_eol (parser); |
| 17296 | } |
| 17297 | |
| 17298 | /* OpenMP 4.5: |
| 17299 | #pragma omp taskloop taskloop-clause[optseq] new-line |
| 17300 | for-loop |
| 17301 | |
| 17302 | #pragma omp taskloop simd taskloop-simd-clause[optseq] new-line |
| 17303 | for-loop */ |
| 17304 | |
| 17305 | #define OMP_TASKLOOP_CLAUSE_MASK \ |
| 17306 | ( (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_SHARED) \ |
| 17307 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIVATE) \ |
| 17308 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ |
| 17309 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ |
| 17310 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_DEFAULT) \ |
| 17311 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_GRAINSIZE) \ |
| 17312 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NUM_TASKS) \ |
| 17313 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_COLLAPSE) \ |
| 17314 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_UNTIED) \ |
| 17315 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_IF) \ |
| 17316 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_FINAL) \ |
| 17317 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_MERGEABLE) \ |
| 17318 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_NOGROUP) \ |
| 17319 | | (OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_PRIORITY)) |
| 17320 | |
| 17321 | static tree |
| 17322 | c_parser_omp_taskloop (location_t loc, c_parser *parser, |
| 17323 | char *p_name, omp_clause_mask mask, tree *cclauses, |
| 17324 | bool *if_p) |
| 17325 | { |
| 17326 | tree clauses, block, ret; |
| 17327 | |
| 17328 | strcat (p_name, " taskloop" ); |
| 17329 | mask |= OMP_TASKLOOP_CLAUSE_MASK; |
| 17330 | |
| 17331 | if (c_parser_next_token_is (parser, CPP_NAME)) |
| 17332 | { |
| 17333 | const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); |
| 17334 | |
| 17335 | if (strcmp (p, "simd" ) == 0) |
| 17336 | { |
| 17337 | tree cclauses_buf[C_OMP_CLAUSE_SPLIT_COUNT]; |
| 17338 | if (cclauses == NULL) |
| 17339 | cclauses = cclauses_buf; |
| 17340 | mask &= ~(OMP_CLAUSE_MASK_1 << PRAGMA_OMP_CLAUSE_REDUCTION); |
| 17341 | c_parser_consume_token (parser); |
| 17342 | if (!flag_openmp) /* flag_openmp_simd */ |
| 17343 | return c_parser_omp_simd (loc, parser, p_name, mask, cclauses, |
| 17344 | if_p); |
| 17345 | block = c_begin_compound_stmt (true); |
| 17346 | ret = c_parser_omp_simd (loc, parser, p_name, mask, cclauses, if_p); |
| 17347 | block = c_end_compound_stmt (loc, block, true); |
| 17348 | if (ret == NULL) |
| 17349 | return ret; |
| 17350 | ret = make_node (OMP_TASKLOOP); |
| 17351 | TREE_TYPE (ret) = void_type_node; |
| 17352 | OMP_FOR_BODY (ret) = block; |
| 17353 | OMP_FOR_CLAUSES (ret) = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP]; |
| 17354 | SET_EXPR_LOCATION (ret, loc); |
| 17355 | add_stmt (ret); |
| 17356 | return ret; |
| 17357 | } |
| 17358 | } |
| 17359 | if (!flag_openmp) /* flag_openmp_simd */ |
| 17360 | { |
| 17361 | c_parser_skip_to_pragma_eol (parser, false); |
| 17362 | return NULL_TREE; |
| 17363 | } |
| 17364 | |
| 17365 | clauses = c_parser_omp_all_clauses (parser, mask, p_name, cclauses == NULL); |
| 17366 | if (cclauses) |
| 17367 | { |
| 17368 | omp_split_clauses (loc, OMP_TASKLOOP, mask, clauses, cclauses); |
| 17369 | clauses = cclauses[C_OMP_CLAUSE_SPLIT_TASKLOOP]; |
| 17370 | } |
| 17371 | |
| 17372 | block = c_begin_compound_stmt (true); |
| 17373 | ret = c_parser_omp_for_loop (loc, parser, OMP_TASKLOOP, clauses, NULL, if_p); |
| 17374 | block = c_end_compound_stmt (loc, block, true); |
| 17375 | add_stmt (block); |
| 17376 | |
| 17377 | return ret; |
| 17378 | } |
| 17379 | |
| 17380 | /* Main entry point to parsing most OpenMP pragmas. */ |
| 17381 | |
| 17382 | static void |
| 17383 | c_parser_omp_construct (c_parser *parser, bool *if_p) |
| 17384 | { |
| 17385 | enum pragma_kind p_kind; |
| 17386 | location_t loc; |
| 17387 | tree stmt; |
| 17388 | char p_name[sizeof "#pragma omp teams distribute parallel for simd" ]; |
| 17389 | omp_clause_mask mask (0); |
| 17390 | |
| 17391 | loc = c_parser_peek_token (parser)->location; |
| 17392 | p_kind = c_parser_peek_token (parser)->pragma_kind; |
| 17393 | c_parser_consume_pragma (parser); |
| 17394 | |
| 17395 | switch (p_kind) |
| 17396 | { |
| 17397 | case PRAGMA_OACC_ATOMIC: |
| 17398 | c_parser_omp_atomic (loc, parser); |
| 17399 | return; |
| 17400 | case PRAGMA_OACC_CACHE: |
| 17401 | strcpy (p_name, "#pragma acc" ); |
| 17402 | stmt = c_parser_oacc_cache (loc, parser); |
| 17403 | break; |
| 17404 | case PRAGMA_OACC_DATA: |
| 17405 | stmt = c_parser_oacc_data (loc, parser, if_p); |
| 17406 | break; |
| 17407 | case PRAGMA_OACC_HOST_DATA: |
| 17408 | stmt = c_parser_oacc_host_data (loc, parser, if_p); |
| 17409 | break; |
| 17410 | case PRAGMA_OACC_KERNELS: |
| 17411 | case PRAGMA_OACC_PARALLEL: |
| 17412 | strcpy (p_name, "#pragma acc" ); |
| 17413 | stmt = c_parser_oacc_kernels_parallel (loc, parser, p_kind, p_name, |
| 17414 | if_p); |
| 17415 | break; |
| 17416 | case PRAGMA_OACC_LOOP: |
| 17417 | strcpy (p_name, "#pragma acc" ); |
| 17418 | stmt = c_parser_oacc_loop (loc, parser, p_name, mask, NULL, if_p); |
| 17419 | break; |
| 17420 | case PRAGMA_OACC_WAIT: |
| 17421 | strcpy (p_name, "#pragma wait" ); |
| 17422 | stmt = c_parser_oacc_wait (loc, parser, p_name); |
| 17423 | break; |
| 17424 | case PRAGMA_OMP_ATOMIC: |
| 17425 | c_parser_omp_atomic (loc, parser); |
| 17426 | return; |
| 17427 | case PRAGMA_OMP_CRITICAL: |
| 17428 | stmt = c_parser_omp_critical (loc, parser, if_p); |
| 17429 | break; |
| 17430 | case PRAGMA_OMP_DISTRIBUTE: |
| 17431 | strcpy (p_name, "#pragma omp" ); |
| 17432 | stmt = c_parser_omp_distribute (loc, parser, p_name, mask, NULL, if_p); |
| 17433 | break; |
| 17434 | case PRAGMA_OMP_FOR: |
| 17435 | strcpy (p_name, "#pragma omp" ); |
| 17436 | stmt = c_parser_omp_for (loc, parser, p_name, mask, NULL, if_p); |
| 17437 | break; |
| 17438 | case PRAGMA_OMP_MASTER: |
| 17439 | stmt = c_parser_omp_master (loc, parser, if_p); |
| 17440 | break; |
| 17441 | case PRAGMA_OMP_PARALLEL: |
| 17442 | strcpy (p_name, "#pragma omp" ); |
| 17443 | stmt = c_parser_omp_parallel (loc, parser, p_name, mask, NULL, if_p); |
| 17444 | break; |
| 17445 | case PRAGMA_OMP_SECTIONS: |
| 17446 | strcpy (p_name, "#pragma omp" ); |
| 17447 | stmt = c_parser_omp_sections (loc, parser, p_name, mask, NULL); |
| 17448 | break; |
| 17449 | case PRAGMA_OMP_SIMD: |
| 17450 | strcpy (p_name, "#pragma omp" ); |
| 17451 | stmt = c_parser_omp_simd (loc, parser, p_name, mask, NULL, if_p); |
| 17452 | break; |
| 17453 | case PRAGMA_OMP_SINGLE: |
| 17454 | stmt = c_parser_omp_single (loc, parser, if_p); |
| 17455 | break; |
| 17456 | case PRAGMA_OMP_TASK: |
| 17457 | stmt = c_parser_omp_task (loc, parser, if_p); |
| 17458 | break; |
| 17459 | case PRAGMA_OMP_TASKGROUP: |
| 17460 | stmt = c_parser_omp_taskgroup (parser, if_p); |
| 17461 | break; |
| 17462 | case PRAGMA_OMP_TASKLOOP: |
| 17463 | strcpy (p_name, "#pragma omp" ); |
| 17464 | stmt = c_parser_omp_taskloop (loc, parser, p_name, mask, NULL, if_p); |
| 17465 | break; |
| 17466 | case PRAGMA_OMP_TEAMS: |
| 17467 | strcpy (p_name, "#pragma omp" ); |
| 17468 | stmt = c_parser_omp_teams (loc, parser, p_name, mask, NULL, if_p); |
| 17469 | break; |
| 17470 | default: |
| 17471 | gcc_unreachable (); |
| 17472 | } |
| 17473 | |
| 17474 | if (stmt) |
| 17475 | gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION); |
| 17476 | } |
| 17477 | |
| 17478 | |
| 17479 | /* OpenMP 2.5: |
| 17480 | # pragma omp threadprivate (variable-list) */ |
| 17481 | |
| 17482 | static void |
| 17483 | c_parser_omp_threadprivate (c_parser *parser) |
| 17484 | { |
| 17485 | tree vars, t; |
| 17486 | location_t loc; |
| 17487 | |
| 17488 | c_parser_consume_pragma (parser); |
| 17489 | loc = c_parser_peek_token (parser)->location; |
| 17490 | vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); |
| 17491 | |
| 17492 | /* Mark every variable in VARS to be assigned thread local storage. */ |
| 17493 | for (t = vars; t; t = TREE_CHAIN (t)) |
| 17494 | { |
| 17495 | tree v = TREE_PURPOSE (t); |
| 17496 | |
| 17497 | /* FIXME diagnostics: Ideally we should keep individual |
| 17498 | locations for all the variables in the var list to make the |
| 17499 | following errors more precise. Perhaps |
| 17500 | c_parser_omp_var_list_parens() should construct a list of |
| 17501 | locations to go along with the var list. */ |
| 17502 | |
| 17503 | /* If V had already been marked threadprivate, it doesn't matter |
| 17504 | whether it had been used prior to this point. */ |
| 17505 | if (!VAR_P (v)) |
| 17506 | error_at (loc, "%qD is not a variable" , v); |
| 17507 | else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v)) |
| 17508 | error_at (loc, "%qE declared %<threadprivate%> after first use" , v); |
| 17509 | else if (! is_global_var (v)) |
| 17510 | error_at (loc, "automatic variable %qE cannot be %<threadprivate%>" , v); |
| 17511 | else if (TREE_TYPE (v) == error_mark_node) |
| 17512 | ; |
| 17513 | else if (! COMPLETE_TYPE_P (TREE_TYPE (v))) |
| 17514 | error_at (loc, "%<threadprivate%> %qE has incomplete type" , v); |
| 17515 | else |
| 17516 | { |
| 17517 | if (! DECL_THREAD_LOCAL_P (v)) |
| 17518 | { |
| 17519 | set_decl_tls_model (v, decl_default_tls_model (v)); |
| 17520 | /* If rtl has been already set for this var, call |
| 17521 | make_decl_rtl once again, so that encode_section_info |
| 17522 | has a chance to look at the new decl flags. */ |
| 17523 | if (DECL_RTL_SET_P (v)) |
| 17524 | make_decl_rtl (v); |
| 17525 | } |
| 17526 | C_DECL_THREADPRIVATE_P (v) = 1; |
| 17527 | } |
| 17528 | } |
| 17529 | |
| 17530 | c_parser_skip_to_pragma_eol (parser); |
| 17531 | } |
| 17532 | |
| 17533 | /* Cilk Plus <#pragma simd> parsing routines. */ |
| 17534 | |
| 17535 | /* Helper function for c_parser_pragma. Perform some sanity checking |
| 17536 | for <#pragma simd> constructs. Returns FALSE if there was a |
| 17537 | problem. */ |
| 17538 | |
| 17539 | static bool |
| 17540 | c_parser_cilk_verify_simd (c_parser *parser, |
| 17541 | enum pragma_context context) |
| 17542 | { |
| 17543 | if (!flag_cilkplus) |
| 17544 | { |
| 17545 | warning (0, "pragma simd ignored because -fcilkplus is not enabled" ); |
| 17546 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
| 17547 | return false; |
| 17548 | } |
| 17549 | if (context == pragma_external) |
| 17550 | { |
| 17551 | c_parser_error (parser,"pragma simd must be inside a function" ); |
| 17552 | c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); |
| 17553 | return false; |
| 17554 | } |
| 17555 | return true; |
| 17556 | } |
| 17557 | |
| 17558 | /* Cilk Plus: |
| 17559 | This function is shared by SIMD-enabled functions and #pragma simd. |
| 17560 | If IS_SIMD_FN is true then it is parsing a SIMD-enabled function and |
| 17561 | CLAUSES is unused. The main purpose of this function is to parse a |
| 17562 | vectorlength attribute or clause and check for parse errors. |
| 17563 | When IS_SIMD_FN is true then the function is merely caching the tokens |
| 17564 | in PARSER->CILK_SIMD_FN_TOKENS. If errors are found then the token |
| 17565 | cache is cleared since there is no reason to continue. |
| 17566 | Syntax: |
| 17567 | vectorlength ( constant-expression ) */ |
| 17568 | |
| 17569 | static tree |
| 17570 | c_parser_cilk_clause_vectorlength (c_parser *parser, tree clauses, |
| 17571 | bool is_simd_fn) |
| 17572 | { |
| 17573 | if (is_simd_fn) |
| 17574 | check_no_duplicate_clause (clauses, OMP_CLAUSE_SIMDLEN, "vectorlength" ); |
| 17575 | else |
| 17576 | /* The vectorlength clause behaves exactly like OpenMP's safelen |
| 17577 | clause. Represent it in OpenMP terms. */ |
| 17578 | check_no_duplicate_clause (clauses, OMP_CLAUSE_SAFELEN, "vectorlength" ); |
| 17579 | |
| 17580 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 17581 | return clauses; |
| 17582 | |
| 17583 | location_t loc = c_parser_peek_token (parser)->location; |
| 17584 | tree expr = c_parser_expr_no_commas (parser, NULL).value; |
| 17585 | expr = c_fully_fold (expr, false, NULL); |
| 17586 | |
| 17587 | /* If expr is an error_mark_node then the above function would have |
| 17588 | emitted an error. No reason to do it twice. */ |
| 17589 | if (expr == error_mark_node) |
| 17590 | ; |
| 17591 | else if (!TREE_TYPE (expr) |
| 17592 | || !TREE_CONSTANT (expr) |
| 17593 | || !INTEGRAL_TYPE_P (TREE_TYPE (expr))) |
| 17594 | |
| 17595 | error_at (loc, "vectorlength must be an integer constant" ); |
| 17596 | else if (wi::exact_log2 (expr) == -1) |
| 17597 | error_at (loc, "vectorlength must be a power of 2" ); |
| 17598 | else |
| 17599 | { |
| 17600 | if (is_simd_fn) |
| 17601 | { |
| 17602 | tree u = build_omp_clause (loc, OMP_CLAUSE_SIMDLEN); |
| 17603 | OMP_CLAUSE_SIMDLEN_EXPR (u) = expr; |
| 17604 | OMP_CLAUSE_CHAIN (u) = clauses; |
| 17605 | clauses = u; |
| 17606 | } |
| 17607 | else |
| 17608 | { |
| 17609 | tree u = build_omp_clause (loc, OMP_CLAUSE_SAFELEN); |
| 17610 | OMP_CLAUSE_SAFELEN_EXPR (u) = expr; |
| 17611 | OMP_CLAUSE_CHAIN (u) = clauses; |
| 17612 | clauses = u; |
| 17613 | } |
| 17614 | } |
| 17615 | |
| 17616 | c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 17617 | |
| 17618 | return clauses; |
| 17619 | } |
| 17620 | |
| 17621 | /* Cilk Plus: |
| 17622 | linear ( simd-linear-variable-list ) |
| 17623 | |
| 17624 | simd-linear-variable-list: |
| 17625 | simd-linear-variable |
| 17626 | simd-linear-variable-list , simd-linear-variable |
| 17627 | |
| 17628 | simd-linear-variable: |
| 17629 | id-expression |
| 17630 | id-expression : simd-linear-step |
| 17631 | |
| 17632 | simd-linear-step: |
| 17633 | conditional-expression */ |
| 17634 | |
| 17635 | static tree |
| 17636 | c_parser_cilk_clause_linear (c_parser *parser, tree clauses) |
| 17637 | { |
| 17638 | if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 17639 | return clauses; |
| 17640 | |
| 17641 | location_t loc = c_parser_peek_token (parser)->location; |
| 17642 | |
| 17643 | if (c_parser_next_token_is_not (parser, CPP_NAME) |
| 17644 | || c_parser_peek_token (parser)->id_kind != C_ID_ID) |
| 17645 | c_parser_error (parser, "expected identifier" ); |
| 17646 | |
| 17647 | while (c_parser_next_token_is (parser, CPP_NAME) |
| 17648 | && c_parser_peek_token (parser)->id_kind == C_ID_ID) |
| 17649 | { |
| 17650 | tree var = lookup_name (c_parser_peek_token (parser)->value); |
| 17651 | |
| 17652 | if (var == NULL) |
| 17653 | { |
| 17654 | undeclared_variable (c_parser_peek_token (parser)->location, |
| 17655 | c_parser_peek_token (parser)->value); |
| 17656 | c_parser_consume_token (parser); |
| 17657 | } |
| 17658 | else if (var == error_mark_node) |
| 17659 | c_parser_consume_token (parser); |
| 17660 | else |
| 17661 | { |
| 17662 | tree step = integer_one_node; |
| 17663 | |
| 17664 | /* Parse the linear step if present. */ |
| 17665 | if (c_parser_peek_2nd_token (parser)->type == CPP_COLON) |
| 17666 | { |
| 17667 | c_parser_consume_token (parser); |
| 17668 | c_parser_consume_token (parser); |
| 17669 | |
| 17670 | tree expr = c_parser_expr_no_commas (parser, NULL).value; |
| 17671 | expr = c_fully_fold (expr, false, NULL); |
| 17672 | |
| 17673 | if (TREE_TYPE (expr) |
| 17674 | && INTEGRAL_TYPE_P (TREE_TYPE (expr)) |
| 17675 | && (TREE_CONSTANT (expr) |
| 17676 | || DECL_P (expr))) |
| 17677 | step = expr; |
| 17678 | else |
| 17679 | c_parser_error (parser, |
| 17680 | "step size must be an integer constant " |
| 17681 | "expression or an integer variable" ); |
| 17682 | } |
| 17683 | else |
| 17684 | c_parser_consume_token (parser); |
| 17685 | |
| 17686 | /* Use OMP_CLAUSE_LINEAR, which has the same semantics. */ |
| 17687 | tree u = build_omp_clause (loc, OMP_CLAUSE_LINEAR); |
| 17688 | OMP_CLAUSE_DECL (u) = var; |
| 17689 | OMP_CLAUSE_LINEAR_STEP (u) = step; |
| 17690 | OMP_CLAUSE_CHAIN (u) = clauses; |
| 17691 | clauses = u; |
| 17692 | } |
| 17693 | |
| 17694 | if (c_parser_next_token_is_not (parser, CPP_COMMA)) |
| 17695 | break; |
| 17696 | |
| 17697 | c_parser_consume_token (parser); |
| 17698 | } |
| 17699 | |
| 17700 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>" ); |
| 17701 | |
| 17702 | return clauses; |
| 17703 | } |
| 17704 | |
| 17705 | /* Returns the name of the next clause. If the clause is not |
| 17706 | recognized SIMD_OMP_CLAUSE_NONE is returned and the next token is |
| 17707 | not consumed. Otherwise, the appropriate pragma_simd_clause is |
| 17708 | returned and the token is consumed. */ |
| 17709 | |
| 17710 | static pragma_omp_clause |
| 17711 | c_parser_cilk_clause_name (c_parser *parser) |
| 17712 | { |
| 17713 | pragma_omp_clause result; |
| 17714 | c_token *token = c_parser_peek_token (parser); |
| 17715 | |
| 17716 | if (!token->value || token->type != CPP_NAME) |
| 17717 | return PRAGMA_CILK_CLAUSE_NONE; |
| 17718 | |
| 17719 | const char *p = IDENTIFIER_POINTER (token->value); |
| 17720 | |
| 17721 | if (!strcmp (p, "vectorlength" )) |
| 17722 | result = PRAGMA_CILK_CLAUSE_VECTORLENGTH; |
| 17723 | else if (!strcmp (p, "linear" )) |
| 17724 | result = PRAGMA_CILK_CLAUSE_LINEAR; |
| 17725 | else if (!strcmp (p, "private" )) |
| 17726 | result = PRAGMA_CILK_CLAUSE_PRIVATE; |
| 17727 | else if (!strcmp (p, "firstprivate" )) |
| 17728 | result = PRAGMA_CILK_CLAUSE_FIRSTPRIVATE; |
| 17729 | else if (!strcmp (p, "lastprivate" )) |
| 17730 | result = PRAGMA_CILK_CLAUSE_LASTPRIVATE; |
| 17731 | else if (!strcmp (p, "reduction" )) |
| 17732 | result = PRAGMA_CILK_CLAUSE_REDUCTION; |
| 17733 | else |
| 17734 | return PRAGMA_CILK_CLAUSE_NONE; |
| 17735 | |
| 17736 | c_parser_consume_token (parser); |
| 17737 | return result; |
| 17738 | } |
| 17739 | |
| 17740 | /* Parse all #<pragma simd> clauses. Return the list of clauses |
| 17741 | found. */ |
| 17742 | |
| 17743 | static tree |
| 17744 | c_parser_cilk_all_clauses (c_parser *parser) |
| 17745 | { |
| 17746 | tree clauses = NULL; |
| 17747 | |
| 17748 | while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) |
| 17749 | { |
| 17750 | pragma_omp_clause c_kind; |
| 17751 | |
| 17752 | c_kind = c_parser_cilk_clause_name (parser); |
| 17753 | |
| 17754 | switch (c_kind) |
| 17755 | { |
| 17756 | case PRAGMA_CILK_CLAUSE_VECTORLENGTH: |
| 17757 | clauses = c_parser_cilk_clause_vectorlength (parser, clauses, false); |
| 17758 | break; |
| 17759 | case PRAGMA_CILK_CLAUSE_LINEAR: |
| 17760 | clauses = c_parser_cilk_clause_linear (parser, clauses); |
| 17761 | break; |
| 17762 | case PRAGMA_CILK_CLAUSE_PRIVATE: |
| 17763 | /* Use the OpenMP counterpart. */ |
| 17764 | clauses = c_parser_omp_clause_private (parser, clauses); |
| 17765 | break; |
| 17766 | case PRAGMA_CILK_CLAUSE_FIRSTPRIVATE: |
| 17767 | /* Use the OpenMP counterpart. */ |
| 17768 | clauses = c_parser_omp_clause_firstprivate (parser, clauses); |
| 17769 | break; |
| 17770 | case PRAGMA_CILK_CLAUSE_LASTPRIVATE: |
| 17771 | /* Use the OpenMP counterpart. */ |
| 17772 | clauses = c_parser_omp_clause_lastprivate (parser, clauses); |
| 17773 | break; |
| 17774 | case PRAGMA_CILK_CLAUSE_REDUCTION: |
| 17775 | /* Use the OpenMP counterpart. */ |
| 17776 | clauses = c_parser_omp_clause_reduction (parser, clauses); |
| 17777 | break; |
| 17778 | default: |
| 17779 | c_parser_error (parser, "expected %<#pragma simd%> clause" ); |
| 17780 | goto saw_error; |
| 17781 | } |
| 17782 | } |
| 17783 | |
| 17784 | saw_error: |
| 17785 | c_parser_skip_to_pragma_eol (parser); |
| 17786 | return c_finish_omp_clauses (clauses, C_ORT_CILK); |
| 17787 | } |
| 17788 | |
| 17789 | /* This function helps parse the grainsize pragma for a _Cilk_for statement. |
| 17790 | Here is the correct syntax of this pragma: |
| 17791 | #pragma cilk grainsize = <EXP> |
| 17792 | */ |
| 17793 | |
| 17794 | static void |
| 17795 | c_parser_cilk_grainsize (c_parser *parser, bool *if_p) |
| 17796 | { |
| 17797 | extern tree convert_to_integer (tree, tree); |
| 17798 | |
| 17799 | /* consume the 'grainsize' keyword. */ |
| 17800 | c_parser_consume_pragma (parser); |
| 17801 | |
| 17802 | if (c_parser_require (parser, CPP_EQ, "expected %<=%>" ) != 0) |
| 17803 | { |
| 17804 | struct c_expr g_expr = c_parser_binary_expression (parser, NULL, NULL); |
| 17805 | if (g_expr.value == error_mark_node) |
| 17806 | { |
| 17807 | c_parser_skip_to_pragma_eol (parser); |
| 17808 | return; |
| 17809 | } |
| 17810 | tree grain = convert_to_integer (long_integer_type_node, |
| 17811 | c_fully_fold (g_expr.value, false, |
| 17812 | NULL)); |
| 17813 | c_parser_skip_to_pragma_eol (parser); |
| 17814 | c_token *token = c_parser_peek_token (parser); |
| 17815 | if (token && token->type == CPP_KEYWORD |
| 17816 | && token->keyword == RID_CILK_FOR) |
| 17817 | { |
| 17818 | if (grain == NULL_TREE || grain == error_mark_node) |
| 17819 | grain = integer_zero_node; |
| 17820 | c_parser_cilk_for (parser, grain, if_p); |
| 17821 | } |
| 17822 | else |
| 17823 | warning (0, "%<#pragma cilk grainsize%> is not followed by " |
| 17824 | "%<_Cilk_for%>" ); |
| 17825 | } |
| 17826 | else |
| 17827 | c_parser_skip_to_pragma_eol (parser); |
| 17828 | } |
| 17829 | |
| 17830 | /* Main entry point for parsing Cilk Plus <#pragma simd> for loops. */ |
| 17831 | |
| 17832 | static void |
| 17833 | c_parser_cilk_simd (c_parser *parser, bool *if_p) |
| 17834 | { |
| 17835 | tree clauses = c_parser_cilk_all_clauses (parser); |
| 17836 | tree block = c_begin_compound_stmt (true); |
| 17837 | location_t loc = c_parser_peek_token (parser)->location; |
| 17838 | c_parser_omp_for_loop (loc, parser, CILK_SIMD, clauses, NULL, if_p); |
| 17839 | block = c_end_compound_stmt (loc, block, true); |
| 17840 | add_stmt (block); |
| 17841 | } |
| 17842 | |
| 17843 | /* Create an artificial decl with TYPE and emit initialization of it with |
| 17844 | INIT. */ |
| 17845 | |
| 17846 | static tree |
| 17847 | c_get_temp_regvar (tree type, tree init) |
| 17848 | { |
| 17849 | location_t loc = EXPR_LOCATION (init); |
| 17850 | tree decl = build_decl (loc, VAR_DECL, NULL_TREE, type); |
| 17851 | DECL_ARTIFICIAL (decl) = 1; |
| 17852 | DECL_IGNORED_P (decl) = 1; |
| 17853 | pushdecl (decl); |
| 17854 | tree t = build2 (INIT_EXPR, type, decl, init); |
| 17855 | add_stmt (t); |
| 17856 | return decl; |
| 17857 | } |
| 17858 | |
| 17859 | /* Main entry point for parsing Cilk Plus _Cilk_for loops. |
| 17860 | GRAIN is the grain value passed in through pragma or 0. */ |
| 17861 | |
| 17862 | static void |
| 17863 | c_parser_cilk_for (c_parser *parser, tree grain, bool *if_p) |
| 17864 | { |
| 17865 | tree clauses = build_omp_clause (EXPR_LOCATION (grain), OMP_CLAUSE_SCHEDULE); |
| 17866 | OMP_CLAUSE_SCHEDULE_KIND (clauses) = OMP_CLAUSE_SCHEDULE_CILKFOR; |
| 17867 | OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (clauses) = grain; |
| 17868 | clauses = c_finish_omp_clauses (clauses, C_ORT_CILK); |
| 17869 | |
| 17870 | tree block = c_begin_compound_stmt (true); |
| 17871 | tree sb = push_stmt_list (); |
| 17872 | location_t loc = c_parser_peek_token (parser)->location; |
| 17873 | tree omp_for = c_parser_omp_for_loop (loc, parser, CILK_FOR, clauses, NULL, |
| 17874 | if_p); |
| 17875 | sb = pop_stmt_list (sb); |
| 17876 | |
| 17877 | if (omp_for) |
| 17878 | { |
| 17879 | tree omp_par = make_node (OMP_PARALLEL); |
| 17880 | TREE_TYPE (omp_par) = void_type_node; |
| 17881 | OMP_PARALLEL_CLAUSES (omp_par) = NULL_TREE; |
| 17882 | tree bind = build3 (BIND_EXPR, void_type_node, NULL, NULL, NULL); |
| 17883 | TREE_SIDE_EFFECTS (bind) = 1; |
| 17884 | BIND_EXPR_BODY (bind) = sb; |
| 17885 | OMP_PARALLEL_BODY (omp_par) = bind; |
| 17886 | if (OMP_FOR_PRE_BODY (omp_for)) |
| 17887 | { |
| 17888 | add_stmt (OMP_FOR_PRE_BODY (omp_for)); |
| 17889 | OMP_FOR_PRE_BODY (omp_for) = NULL_TREE; |
| 17890 | } |
| 17891 | tree init = TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0); |
| 17892 | tree decl = TREE_OPERAND (init, 0); |
| 17893 | tree cond = TREE_VEC_ELT (OMP_FOR_COND (omp_for), 0); |
| 17894 | tree incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0); |
| 17895 | tree t = TREE_OPERAND (cond, 1), c, clauses = NULL_TREE; |
| 17896 | if (TREE_CODE (t) != INTEGER_CST) |
| 17897 | { |
| 17898 | TREE_OPERAND (cond, 1) = c_get_temp_regvar (TREE_TYPE (t), t); |
| 17899 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); |
| 17900 | OMP_CLAUSE_DECL (c) = TREE_OPERAND (cond, 1); |
| 17901 | OMP_CLAUSE_CHAIN (c) = clauses; |
| 17902 | clauses = c; |
| 17903 | } |
| 17904 | if (TREE_CODE (incr) == MODIFY_EXPR) |
| 17905 | { |
| 17906 | t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1); |
| 17907 | if (TREE_CODE (t) != INTEGER_CST) |
| 17908 | { |
| 17909 | TREE_OPERAND (TREE_OPERAND (incr, 1), 1) |
| 17910 | = c_get_temp_regvar (TREE_TYPE (t), t); |
| 17911 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); |
| 17912 | OMP_CLAUSE_DECL (c) = TREE_OPERAND (TREE_OPERAND (incr, 1), 1); |
| 17913 | OMP_CLAUSE_CHAIN (c) = clauses; |
| 17914 | clauses = c; |
| 17915 | } |
| 17916 | } |
| 17917 | t = TREE_OPERAND (init, 1); |
| 17918 | if (TREE_CODE (t) != INTEGER_CST) |
| 17919 | { |
| 17920 | TREE_OPERAND (init, 1) = c_get_temp_regvar (TREE_TYPE (t), t); |
| 17921 | c = build_omp_clause (input_location, OMP_CLAUSE_FIRSTPRIVATE); |
| 17922 | OMP_CLAUSE_DECL (c) = TREE_OPERAND (init, 1); |
| 17923 | OMP_CLAUSE_CHAIN (c) = clauses; |
| 17924 | clauses = c; |
| 17925 | } |
| 17926 | c = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE); |
| 17927 | OMP_CLAUSE_DECL (c) = decl; |
| 17928 | OMP_CLAUSE_CHAIN (c) = clauses; |
| 17929 | clauses = c; |
| 17930 | c = build_omp_clause (input_location, OMP_CLAUSE__CILK_FOR_COUNT_); |
| 17931 | OMP_CLAUSE_OPERAND (c, 0) |
| 17932 | = cilk_for_number_of_iterations (omp_for); |
| 17933 | OMP_CLAUSE_CHAIN (c) = clauses; |
| 17934 | OMP_PARALLEL_CLAUSES (omp_par) = c_finish_omp_clauses (c, C_ORT_CILK); |
| 17935 | add_stmt (omp_par); |
| 17936 | } |
| 17937 | |
| 17938 | block = c_end_compound_stmt (loc, block, true); |
| 17939 | add_stmt (block); |
| 17940 | } |
| 17941 | |
| 17942 | |
| 17943 | /* Parse a transaction attribute (GCC Extension). |
| 17944 | |
| 17945 | transaction-attribute: |
| 17946 | attributes |
| 17947 | [ [ any-word ] ] |
| 17948 | |
| 17949 | The transactional memory language description is written for C++, |
| 17950 | and uses the C++0x attribute syntax. For compatibility, allow the |
| 17951 | bracket style for transactions in C as well. */ |
| 17952 | |
| 17953 | static tree |
| 17954 | c_parser_transaction_attributes (c_parser *parser) |
| 17955 | { |
| 17956 | tree attr_name, attr = NULL; |
| 17957 | |
| 17958 | if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) |
| 17959 | return c_parser_attributes (parser); |
| 17960 | |
| 17961 | if (!c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) |
| 17962 | return NULL_TREE; |
| 17963 | c_parser_consume_token (parser); |
| 17964 | if (!c_parser_require (parser, CPP_OPEN_SQUARE, "expected %<[%>" )) |
| 17965 | goto error1; |
| 17966 | |
| 17967 | attr_name = c_parser_attribute_any_word (parser); |
| 17968 | if (attr_name) |
| 17969 | { |
| 17970 | c_parser_consume_token (parser); |
| 17971 | attr = build_tree_list (attr_name, NULL_TREE); |
| 17972 | } |
| 17973 | else |
| 17974 | c_parser_error (parser, "expected identifier" ); |
| 17975 | |
| 17976 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>" ); |
| 17977 | error1: |
| 17978 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>" ); |
| 17979 | return attr; |
| 17980 | } |
| 17981 | |
| 17982 | /* Parse a __transaction_atomic or __transaction_relaxed statement |
| 17983 | (GCC Extension). |
| 17984 | |
| 17985 | transaction-statement: |
| 17986 | __transaction_atomic transaction-attribute[opt] compound-statement |
| 17987 | __transaction_relaxed compound-statement |
| 17988 | |
| 17989 | Note that the only valid attribute is: "outer". |
| 17990 | */ |
| 17991 | |
| 17992 | static tree |
| 17993 | c_parser_transaction (c_parser *parser, enum rid keyword) |
| 17994 | { |
| 17995 | unsigned int old_in = parser->in_transaction; |
| 17996 | unsigned int this_in = 1, new_in; |
| 17997 | location_t loc = c_parser_peek_token (parser)->location; |
| 17998 | tree stmt, attrs; |
| 17999 | |
| 18000 | gcc_assert ((keyword == RID_TRANSACTION_ATOMIC |
| 18001 | || keyword == RID_TRANSACTION_RELAXED) |
| 18002 | && c_parser_next_token_is_keyword (parser, keyword)); |
| 18003 | c_parser_consume_token (parser); |
| 18004 | |
| 18005 | if (keyword == RID_TRANSACTION_RELAXED) |
| 18006 | this_in |= TM_STMT_ATTR_RELAXED; |
| 18007 | else |
| 18008 | { |
| 18009 | attrs = c_parser_transaction_attributes (parser); |
| 18010 | if (attrs) |
| 18011 | this_in |= parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER); |
| 18012 | } |
| 18013 | |
| 18014 | /* Keep track if we're in the lexical scope of an outer transaction. */ |
| 18015 | new_in = this_in | (old_in & TM_STMT_ATTR_OUTER); |
| 18016 | |
| 18017 | parser->in_transaction = new_in; |
| 18018 | stmt = c_parser_compound_statement (parser); |
| 18019 | parser->in_transaction = old_in; |
| 18020 | |
| 18021 | if (flag_tm) |
| 18022 | stmt = c_finish_transaction (loc, stmt, this_in); |
| 18023 | else |
| 18024 | error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ? |
| 18025 | "%<__transaction_atomic%> without transactional memory support enabled" |
| 18026 | : "%<__transaction_relaxed %> " |
| 18027 | "without transactional memory support enabled" )); |
| 18028 | |
| 18029 | return stmt; |
| 18030 | } |
| 18031 | |
| 18032 | /* Parse a __transaction_atomic or __transaction_relaxed expression |
| 18033 | (GCC Extension). |
| 18034 | |
| 18035 | transaction-expression: |
| 18036 | __transaction_atomic ( expression ) |
| 18037 | __transaction_relaxed ( expression ) |
| 18038 | */ |
| 18039 | |
| 18040 | static struct c_expr |
| 18041 | c_parser_transaction_expression (c_parser *parser, enum rid keyword) |
| 18042 | { |
| 18043 | struct c_expr ret; |
| 18044 | unsigned int old_in = parser->in_transaction; |
| 18045 | unsigned int this_in = 1; |
| 18046 | location_t loc = c_parser_peek_token (parser)->location; |
| 18047 | tree attrs; |
| 18048 | |
| 18049 | gcc_assert ((keyword == RID_TRANSACTION_ATOMIC |
| 18050 | || keyword == RID_TRANSACTION_RELAXED) |
| 18051 | && c_parser_next_token_is_keyword (parser, keyword)); |
| 18052 | c_parser_consume_token (parser); |
| 18053 | |
| 18054 | if (keyword == RID_TRANSACTION_RELAXED) |
| 18055 | this_in |= TM_STMT_ATTR_RELAXED; |
| 18056 | else |
| 18057 | { |
| 18058 | attrs = c_parser_transaction_attributes (parser); |
| 18059 | if (attrs) |
| 18060 | this_in |= parse_tm_stmt_attr (attrs, 0); |
| 18061 | } |
| 18062 | |
| 18063 | parser->in_transaction = this_in; |
| 18064 | if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>" )) |
| 18065 | { |
| 18066 | tree expr = c_parser_expression (parser).value; |
| 18067 | ret.original_type = TREE_TYPE (expr); |
| 18068 | ret.value = build1 (TRANSACTION_EXPR, ret.original_type, expr); |
| 18069 | if (this_in & TM_STMT_ATTR_RELAXED) |
| 18070 | TRANSACTION_EXPR_RELAXED (ret.value) = 1; |
| 18071 | SET_EXPR_LOCATION (ret.value, loc); |
| 18072 | ret.original_code = TRANSACTION_EXPR; |
| 18073 | if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>" )) |
| 18074 | { |
| 18075 | c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); |
| 18076 | goto error; |
| 18077 | } |
| 18078 | } |
| 18079 | else |
| 18080 | { |
| 18081 | error: |
| 18082 | ret.value = error_mark_node; |
| 18083 | ret.original_code = ERROR_MARK; |
| 18084 | ret.original_type = NULL; |
| 18085 | } |
| 18086 | parser->in_transaction = old_in; |
| 18087 | |
| 18088 | if (!flag_tm) |
| 18089 | error_at (loc, (keyword == RID_TRANSACTION_ATOMIC ? |
| 18090 | "%<__transaction_atomic%> without transactional memory support enabled" |
| 18091 | : "%<__transaction_relaxed %> " |
| 18092 | "without transactional memory support enabled" )); |
| 18093 | |
| 18094 | set_c_expr_source_range (&ret, loc, loc); |
| 18095 | |
| 18096 | return ret; |
| 18097 | } |
| 18098 | |
| 18099 | /* Parse a __transaction_cancel statement (GCC Extension). |
| 18100 | |
| 18101 | transaction-cancel-statement: |
| 18102 | __transaction_cancel transaction-attribute[opt] ; |
| 18103 | |
| 18104 | Note that the only valid attribute is "outer". |
| 18105 | */ |
| 18106 | |
| 18107 | static tree |
| 18108 | c_parser_transaction_cancel (c_parser *parser) |
| 18109 | { |
| 18110 | location_t loc = c_parser_peek_token (parser)->location; |
| 18111 | tree attrs; |
| 18112 | bool is_outer = false; |
| 18113 | |
| 18114 | gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRANSACTION_CANCEL)); |
| 18115 | c_parser_consume_token (parser); |
| 18116 | |
| 18117 | attrs = c_parser_transaction_attributes (parser); |
| 18118 | if (attrs) |
| 18119 | is_outer = (parse_tm_stmt_attr (attrs, TM_STMT_ATTR_OUTER) != 0); |
| 18120 | |
| 18121 | if (!flag_tm) |
| 18122 | { |
| 18123 | error_at (loc, "%<__transaction_cancel%> without " |
| 18124 | "transactional memory support enabled" ); |
| 18125 | goto ret_error; |
| 18126 | } |
| 18127 | else if (parser->in_transaction & TM_STMT_ATTR_RELAXED) |
| 18128 | { |
| 18129 | error_at (loc, "%<__transaction_cancel%> within a " |
| 18130 | "%<__transaction_relaxed%>" ); |
| 18131 | goto ret_error; |
| 18132 | } |
| 18133 | else if (is_outer) |
| 18134 | { |
| 18135 | if ((parser->in_transaction & TM_STMT_ATTR_OUTER) == 0 |
| 18136 | && !is_tm_may_cancel_outer (current_function_decl)) |
| 18137 | { |
| 18138 | error_at (loc, "outer %<__transaction_cancel%> not " |
| 18139 | "within outer %<__transaction_atomic%>" ); |
| 18140 | error_at (loc, " or a %<transaction_may_cancel_outer%> function" ); |
| 18141 | goto ret_error; |
| 18142 | } |
| 18143 | } |
| 18144 | else if (parser->in_transaction == 0) |
| 18145 | { |
| 18146 | error_at (loc, "%<__transaction_cancel%> not within " |
| 18147 | "%<__transaction_atomic%>" ); |
| 18148 | goto ret_error; |
| 18149 | } |
| 18150 | |
| 18151 | return add_stmt (build_tm_abort_call (loc, is_outer)); |
| 18152 | |
| 18153 | ret_error: |
| 18154 | return build1 (NOP_EXPR, void_type_node, error_mark_node); |
| 18155 | } |
| 18156 | |
| 18157 | /* Parse a single source file. */ |
| 18158 | |
| 18159 | void |
| 18160 | c_parse_file (void) |
| 18161 | { |
| 18162 | /* Use local storage to begin. If the first token is a pragma, parse it. |
| 18163 | If it is #pragma GCC pch_preprocess, then this will load a PCH file |
| 18164 | which will cause garbage collection. */ |
| 18165 | c_parser tparser; |
| 18166 | |
| 18167 | memset (&tparser, 0, sizeof tparser); |
| 18168 | tparser.tokens = &tparser.tokens_buf[0]; |
| 18169 | the_parser = &tparser; |
| 18170 | |
| 18171 | if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS) |
| 18172 | c_parser_pragma_pch_preprocess (&tparser); |
| 18173 | |
| 18174 | the_parser = ggc_alloc<c_parser> (); |
| 18175 | *the_parser = tparser; |
| 18176 | if (tparser.tokens == &tparser.tokens_buf[0]) |
| 18177 | the_parser->tokens = &the_parser->tokens_buf[0]; |
| 18178 | |
| 18179 | /* Initialize EH, if we've been told to do so. */ |
| 18180 | if (flag_exceptions) |
| 18181 | using_eh_for_cleanups (); |
| 18182 | |
| 18183 | c_parser_translation_unit (the_parser); |
| 18184 | the_parser = NULL; |
| 18185 | } |
| 18186 | |
| 18187 | /* This function parses Cilk Plus array notation. The starting index is |
| 18188 | passed in INITIAL_INDEX and the array name is passes in ARRAY_VALUE. The |
| 18189 | return value of this function is a tree_node called VALUE_TREE of type |
| 18190 | ARRAY_NOTATION_REF. */ |
| 18191 | |
| 18192 | static tree |
| 18193 | c_parser_array_notation (location_t loc, c_parser *parser, tree initial_index, |
| 18194 | tree array_value) |
| 18195 | { |
| 18196 | c_token *token = NULL; |
| 18197 | tree start_index = NULL_TREE, end_index = NULL_TREE, stride = NULL_TREE; |
| 18198 | tree value_tree = NULL_TREE, type = NULL_TREE, array_type = NULL_TREE; |
| 18199 | tree array_type_domain = NULL_TREE; |
| 18200 | |
| 18201 | if (array_value == error_mark_node || initial_index == error_mark_node) |
| 18202 | { |
| 18203 | /* No need to continue. If either of these 2 were true, then an error |
| 18204 | must be emitted already. Thus, no need to emit them twice. */ |
| 18205 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); |
| 18206 | return error_mark_node; |
| 18207 | } |
| 18208 | |
| 18209 | array_type = TREE_TYPE (array_value); |
| 18210 | gcc_assert (array_type); |
| 18211 | if (TREE_CODE (array_type) != ARRAY_TYPE |
| 18212 | && TREE_CODE (array_type) != POINTER_TYPE) |
| 18213 | { |
| 18214 | error_at (loc, "base of array section must be pointer or array type" ); |
| 18215 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); |
| 18216 | return error_mark_node; |
| 18217 | } |
| 18218 | type = TREE_TYPE (array_type); |
| 18219 | token = c_parser_peek_token (parser); |
| 18220 | |
| 18221 | if (token->type == CPP_EOF) |
| 18222 | { |
| 18223 | c_parser_error (parser, "expected %<:%> or numeral" ); |
| 18224 | return value_tree; |
| 18225 | } |
| 18226 | else if (token->type == CPP_COLON) |
| 18227 | { |
| 18228 | if (!initial_index) |
| 18229 | { |
| 18230 | /* If we are here, then we have a case like this A[:]. */ |
| 18231 | c_parser_consume_token (parser); |
| 18232 | if (TREE_CODE (array_type) == POINTER_TYPE) |
| 18233 | { |
| 18234 | error_at (loc, "start-index and length fields necessary for " |
| 18235 | "using array notations in pointers" ); |
| 18236 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); |
| 18237 | return error_mark_node; |
| 18238 | } |
| 18239 | if (TREE_CODE (array_type) == FUNCTION_TYPE) |
| 18240 | { |
| 18241 | error_at (loc, "array notations cannot be used with function " |
| 18242 | "type" ); |
| 18243 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); |
| 18244 | return error_mark_node; |
| 18245 | } |
| 18246 | array_type_domain = TYPE_DOMAIN (array_type); |
| 18247 | |
| 18248 | if (!array_type_domain) |
| 18249 | { |
| 18250 | error_at (loc, "start-index and length fields necessary for " |
| 18251 | "using array notations in dimensionless arrays" ); |
| 18252 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); |
| 18253 | return error_mark_node; |
| 18254 | } |
| 18255 | |
| 18256 | start_index = TYPE_MINVAL (array_type_domain); |
| 18257 | start_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, |
| 18258 | start_index); |
| 18259 | if (!TYPE_MAXVAL (array_type_domain) |
| 18260 | || !TREE_CONSTANT (TYPE_MAXVAL (array_type_domain))) |
| 18261 | { |
| 18262 | error_at (loc, "start-index and length fields necessary for " |
| 18263 | "using array notations in variable-length arrays" ); |
| 18264 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); |
| 18265 | return error_mark_node; |
| 18266 | } |
| 18267 | end_index = TYPE_MAXVAL (array_type_domain); |
| 18268 | end_index = fold_build2 (PLUS_EXPR, TREE_TYPE (end_index), |
| 18269 | end_index, integer_one_node); |
| 18270 | end_index = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, end_index); |
| 18271 | stride = build_int_cst (integer_type_node, 1); |
| 18272 | stride = fold_build1 (CONVERT_EXPR, ptrdiff_type_node, stride); |
| 18273 | } |
| 18274 | else if (initial_index != error_mark_node) |
| 18275 | { |
| 18276 | /* If we are here, then there should be 2 possibilities: |
| 18277 | 1. Array [EXPR : EXPR] |
| 18278 | 2. Array [EXPR : EXPR : EXPR] |
| 18279 | */ |
| 18280 | start_index = initial_index; |
| 18281 | |
| 18282 | if (TREE_CODE (array_type) == FUNCTION_TYPE) |
| 18283 | { |
| 18284 | error_at (loc, "array notations cannot be used with function " |
| 18285 | "type" ); |
| 18286 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); |
| 18287 | return error_mark_node; |
| 18288 | } |
| 18289 | c_parser_consume_token (parser); /* consume the ':' */ |
| 18290 | struct c_expr ce = c_parser_expression (parser); |
| 18291 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); |
| 18292 | end_index = ce.value; |
| 18293 | if (!end_index || end_index == error_mark_node) |
| 18294 | { |
| 18295 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 18296 | return error_mark_node; |
| 18297 | } |
| 18298 | if (c_parser_peek_token (parser)->type == CPP_COLON) |
| 18299 | { |
| 18300 | c_parser_consume_token (parser); |
| 18301 | ce = c_parser_expression (parser); |
| 18302 | ce = convert_lvalue_to_rvalue (loc, ce, false, false); |
| 18303 | stride = ce.value; |
| 18304 | if (!stride || stride == error_mark_node) |
| 18305 | { |
| 18306 | c_parser_skip_to_end_of_block_or_statement (parser); |
| 18307 | return error_mark_node; |
| 18308 | } |
| 18309 | } |
| 18310 | } |
| 18311 | else |
| 18312 | c_parser_error (parser, "expected array notation expression" ); |
| 18313 | } |
| 18314 | else |
| 18315 | c_parser_error (parser, "expected array notation expression" ); |
| 18316 | |
| 18317 | c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>" ); |
| 18318 | |
| 18319 | value_tree = build_array_notation_ref (loc, array_value, start_index, |
| 18320 | end_index, stride, type); |
| 18321 | if (value_tree != error_mark_node) |
| 18322 | SET_EXPR_LOCATION (value_tree, loc); |
| 18323 | return value_tree; |
| 18324 | } |
| 18325 | |
| 18326 | /* Parse the body of a function declaration marked with "__RTL". |
| 18327 | |
| 18328 | The RTL parser works on the level of characters read from a |
| 18329 | FILE *, whereas c_parser works at the level of tokens. |
| 18330 | Square this circle by consuming all of the tokens up to and |
| 18331 | including the closing brace, recording the start/end of the RTL |
| 18332 | fragment, and reopening the file and re-reading the relevant |
| 18333 | lines within the RTL parser. |
| 18334 | |
| 18335 | This requires the opening and closing braces of the C function |
| 18336 | to be on separate lines from the RTL they wrap. |
| 18337 | |
| 18338 | Take ownership of START_WITH_PASS, if non-NULL. */ |
| 18339 | |
| 18340 | void |
| 18341 | c_parser_parse_rtl_body (c_parser *parser, char *start_with_pass) |
| 18342 | { |
| 18343 | if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>" )) |
| 18344 | { |
| 18345 | free (start_with_pass); |
| 18346 | return; |
| 18347 | } |
| 18348 | |
| 18349 | location_t start_loc = c_parser_peek_token (parser)->location; |
| 18350 | |
| 18351 | /* Consume all tokens, up to the closing brace, handling |
| 18352 | matching pairs of braces in the rtl dump. */ |
| 18353 | int num_open_braces = 1; |
| 18354 | while (1) |
| 18355 | { |
| 18356 | switch (c_parser_peek_token (parser)->type) |
| 18357 | { |
| 18358 | case CPP_OPEN_BRACE: |
| 18359 | num_open_braces++; |
| 18360 | break; |
| 18361 | case CPP_CLOSE_BRACE: |
| 18362 | if (--num_open_braces == 0) |
| 18363 | goto found_closing_brace; |
| 18364 | break; |
| 18365 | case CPP_EOF: |
| 18366 | error_at (start_loc, "no closing brace" ); |
| 18367 | free (start_with_pass); |
| 18368 | return; |
| 18369 | default: |
| 18370 | break; |
| 18371 | } |
| 18372 | c_parser_consume_token (parser); |
| 18373 | } |
| 18374 | |
| 18375 | found_closing_brace: |
| 18376 | /* At the closing brace; record its location. */ |
| 18377 | location_t end_loc = c_parser_peek_token (parser)->location; |
| 18378 | |
| 18379 | /* Consume the closing brace. */ |
| 18380 | c_parser_consume_token (parser); |
| 18381 | |
| 18382 | /* Invoke the RTL parser. */ |
| 18383 | if (!read_rtl_function_body_from_file_range (start_loc, end_loc)) |
| 18384 | { |
| 18385 | free (start_with_pass); |
| 18386 | return; |
| 18387 | } |
| 18388 | |
| 18389 | /* If a pass name was provided for START_WITH_PASS, run the backend |
| 18390 | accordingly now, on the cfun created above, transferring |
| 18391 | ownership of START_WITH_PASS. */ |
| 18392 | if (start_with_pass) |
| 18393 | run_rtl_passes (start_with_pass); |
| 18394 | } |
| 18395 | |
| 18396 | #include "gt-c-c-parser.h" |
| 18397 | |